TOGOUTECH

ngOnDestroy

全部标签

javascript - clearinterval 在 ngOnDestroy() 内部不起作用

我的ngOndestroy正在调用其他路由导航,但它没有在方法内部执行clearInterval。我哪里做错了?当我在其他组件中时,它在后台运行。timer:any;ngOnInit(){this.timer=this.interval();};ngOnDestroy(){clearInterval(this.timer);console.log("InsideDestroy");}interval(){setInterval(()=>{this.getData();},20000)}getData(){this.dataservice.getdata().sub

javascript - Angular 2 - ngOnDestroy 未触发

演示http://plnkr.co/edit/7uoVecfa62i8No8GtQHI?p=preview当我使用*ngIf隐藏带有嵌套组件的第一部分时,会触发每个嵌套组件的ngOnDestroy。<div*ngIf="!ff2"><my-component></my-component><my-component></my-component><my-component></my-component><my-component></my-component>&l