SUB*_*DAL 10 javascript angular
我的ngOndestroy正在调用其他路由导航,但它没有在方法中执行clearInterval.我哪里弄错了?它在后台运行,而我在其他组件中.
timer:any;
ngOnInit() {
this.timer= this.interval();
};
ngOnDestroy(){
clearInterval(this.timer);
console.log("Inside Destroy");
}
interval(){
setInterval(()=>{
this.getData();
},20000)
}
getData(){
this.dataservice.getdata()
.subscribe(users=>{
this.datas=users;
console.log(this.datas);
})
}
Run Code Online (Sandbox Code Playgroud)
你忘了返回间隔的实例.
interval(){
return setInterval(()=>{
this.getData();
},20000)
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
597 次 |
| 最近记录: |