【发布时间】:2021-04-19 17:51:31
【问题描述】:
在 Angular 中,我使用了一个返回 Promise 的简单函数,在“then”函数中,我更改了 Img html 标记的 src。 当我从 NgOnInit(或从 onclick)调用此函数时,html 将不会更新,直到我通过再次单击某些内容来强制重新加载内容。但 colsole.log 工作。
click1() {
this.loadCaptcha();
}
ngOnInit(): void {
this.loadCaptcha();
}
loadCaptcha() {
this.apiService.getCaptcha()
.then((data) => {
this.image = 'http://....' + data.id;
console.log(data);
});
}
<img [src]='image' (click)="click1()" />
【问题讨论】:
标签: angular promise binding ngoninit