我已經嘗試過幾乎所有可以找到的東西,並且似乎無法獲取此間隔以停止執行訂閱中的代碼。我使用間隔錯誤?不能停止可觀察間隔
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