【发布时间】:2017-10-06 04:33:03
【问题描述】:
我已经尝试了几乎所有我能找到的东西,但似乎无法让这个时间间隔停止在订阅中执行代码。是不是我用错了区间?
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();
});
但发生这种情况后,我仍然看到控制台日志语句显示“推送新项目”,就好像它仍在我的时间间隔内运行一样。
【问题讨论】:
-
您可以在
subscribe()中调用subscription.unsubcscribe()。或者我不明白你想做什么......