Reputation: 142
this.fetchRequests(this) gets executed as soon as the view is initialized instead of waiting for 20 seconds.
I am aware in the older versions we have to use the wrapper but in the new versions those are not required I guess. Any help on this would be helpful.
ngAfterViewInit() {
setTimeout(()=>{
this.fetchRequests(this);
}), 10000;
}
Upvotes: 3
Views: 8783
Reputation: 1851
your syntax is wrong
two syntax's are here for function one which is blow new one
setTimeout(()=>{
this.fetchRequests(this);
},1000);
and second below syntax is old one you can use both of them
setTimeout(function(){
this.fetchRequests(this);
},1000);
both are functional in Angular 9- Typescript and Nodejs and latest javascript version by now
Upvotes: 1
Reputation: 4388
I think you write the wrong syntax this code
setTimeout(()=>{
this.fetchRequests(this);
}), 10000;
should be like this
setTimeout(()=>{ this.fetchRequests(this); },1000);
Upvotes: 9
Reputation: 951
Wrap it in zone.run()
.
First, import NgZone
from @angular/core
, and inject it into your component.
Then, modify your ngAfterViewInit to look like this:
ngAfterViewInit() {
this.zone.run(() => {
setTimeout(()=>{
this.fetchRequests(this);
}, 10000);
});
}
Upvotes: 4