Angular binding in Promise not work in ngOnInit
In Angular, I use a simple function that return a Promise and in ‘then’ function I change src of an Img html tag.
when I call this function from an OnClick function, everything is ok, but when i call it from NgOnInit, html will not update until i force the content to reload by another click on something.
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" />
Source: Angular Questions