我已经尝试过几乎所有可以找到的东西,并且似乎无法获取此间隔以停止执行订阅中的代码。我使用间隔错误?不能停止可观察间隔
var subject = new Subject();
var interval = Observable.interval(this.settings.timing * 1000);
var subscription = interval
.takeUntil(subject)
.subscribe(t => {
console.log('pushing new item');
this.activeItems[0].contentLeaving = true;
setTimeout(()=>{
this.activeItems[0].imageLeaving = true;
setTimeout(()=>{
this.activeItems.push(this.activeItems.shift());
setTimeout(()=>{
this.activeItems[1].contentLeaving = false;
this.activeItems[1].imageLeaving = false;
},510);
},510);
},510);
});
this.moduleProps.intervals.push(subject);
在我ngOnDestroy
this.moduleProps.intervals.forEach((i)=>{
i.complete();
});
但毕竟这发生了,我仍然看到控制台日志声明,称“推新项目”,如果它仍然在我的区间运行。
你可以叫'subscription.unsubcscribe()''内部认购()'。或者,也许我不明白你想要做什么... – martin