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