I am trying to learn the concept of promise and implement in angular. Here is my code in stackblit. What I am trying to achieve is , I have want to show the array whenever it is assigned with any value using promise in angular.
My Html Code is :
<h2>Array values</h2>
<p *ngIf="show">
<span *ngFor="let values of filter">
{{values}}
</span>
</p>
My TS file is :
filter = [];
show = false;
ngOnInit() {
this.showArray();
}
showArray() {
var a = new Promise(resolve=>{
setTimeout(() => {
this.filter = [3, 4, 4]
resolve('resolved');
}, 0);
});
a.then(function() {
this.show= true;
})
}
Whenever my array is assigned with any values(which might be from a remote API), I want to set the variable show to true. I am not getting the result. I have gone through many examples related to promise but couldn't found a working example of promise in this fashion.