我正在尝试取消 ionic2 上的主页选项卡上的一个 observable,这可能是那里的一个错误,因为现在 6 小时后没有任何效果。
我正在使用的可观察示例来自此站点 https://coryrylan.com/blog/intro-to-rxjs-observables-and-angular-2
我试过 ngZone,你不能从 ngZone 清除间隔,
我试过了
ionViewWillLeave() {
this.disposable.dispose();
clearInterval(this.home_game_timer);
}
没有任何效果..这是代码...此代码在主页选项卡上
getGame(){
var link = 'https://gamerholic.com/******';
var data_post = JSON.stringify({game:this.game,uid:this.data.uid,device:this.device_id,session:this.session});
let headers = new Headers({ 'Content-Type': 'application/json' }); // ... Set content type to JSON
let options = new RequestOptions({ headers: headers }); // Create a request option
return this.http.post(link, data_post, options) // ...using post request
.map(data => data.json())
.catch(this.handleError)
.subscribe((data) =>{
this.game_data = data
if(this.game_data.success){
this.game = this.game_data.games[0].id,
this.game_data = this.game_data.games[0]
this.gameStream$ = new Observable(observer=>{
this.home_game_timer = setInterval(()=>{
if(this.gone<1){
var link = 'https://gamerholic.com/****';
var data = JSON.stringify({game:this.game,uid:this.uid});
let headers = new Headers({ 'Content-Type' : 'application/x-www-form-urlencoded; charset=UTF-8' });
let options = new RequestOptions({ headers: headers });
return this.http.post(link, data,options)
.map(data => data.json())
.catch(this.handleError)
.subscribe((data) =>{
var d = data
observer.next(d)
})
}
},1000)
return(()=>{
clearInterval(this.home_game_timer);
})
})
this.disposable = this.gameStream$.subscribe((data)=>{
this.timer_data = data
this.list_players = data
console.log(this.timer_data)
})
}
})
}