ionic应用切换触发更新

474

ionic文档:http://ionicframework.com/docs/api/platform/Platform/

 

ionViewDidLoad() {
this.platform.ready().then(() => {
this.platform.pause.subscribe(() => {
this.connectState = ‘disconnected’;
this.connected = false;
this.buttonDisabled = true;
});
this.platform.resume.subscribe(() => {
this.checkConnectivity();
});
}

 

2017.11.9

发现,取消订阅resume后,无法再次订阅,如果再次订阅就会报错:

Error: Uncaught (in promise): ObjectUnsubscribedError: object unsubscribed

我的写法:

  ngOnInit() {
    console.log("PlugConfigPage OnInit");
    this.platformResume=this.platform.resume.subscribe(() => {
      console.log("resume subscribe")
    });
  }

  ngOnDestroy() {
    console.log("PlugConfigPage OnDestroy");
    this.platform.resume.unsubscribe();
  }

其实这个写法是错误的,正确写法为:

  ngOnInit() {
    console.log("PlugConfigPage OnInit");
    this.platformResume=this.platform.resume.subscribe(() => {
      console.log("resume")
    });
  }

  ngOnDestroy() {
    console.log("PlugConfigPage OnDestroy");
    this.platformResume.unsubscribe();
  }

 

 

留下一个答复

Please enter your comment!
Please enter your name here