0
以下是我的组件,我希望使用Promise显示图像。以下是我的代码,浏览器运行时无响应。 任何人都可以帮助我解决这个问题。Angular2:如何使用Promise显示图像?
HTML:
<img [src]="getImage()" />
JS: my.component.ts
// ...
public imageUrl:string;
constructor() {
this.imageUrl = "path-to-my-image/image.png";
}
getImage(){
return new Promise((resolve,reject) =>{
// this.imageUrl is not static one, it may fetch from the server
resolve(this.imageUrl);
});
}
// ...
谢谢,它现在正在工作。 –
嗨,还有一个疑问。图像列表如何解决这个问题?我想在side * ngFor中使用用户图像。在这种情况下,我无法创建像'this.image $'这样的Observable对象,请帮助我。 代码看起来像:
根据你想要做什么,考虑一个url数组的可观察值。然后你可以说''。 – 2017-05-07 12:49:04