Quantcast
Channel: Ionic Forum - Latest topics
Viewing all articles
Browse latest Browse all 71531

ViewDestroyed error when change detection done on an active component

$
0
0

@rajeevriitm wrote:

Here is the work flow of my Ionic app.

App starts with Welcome Page - > Login -> Service on background checks for new notification and emits a “new-event” -> After login, Home page -> New page which is subscribed to “new-event” triggers a change detection.

But I get an error

ViewDestroyedError: Attempt to use a destroyed view: detectChanges

Here is the relevant code.

WelcomePage

login(){
  this.auth.login().then(()=>{
    this.navCtrl.setRoot('TabsPage');
  })
}

TabPage has a HomePage which has HeaderComponent

HomePage

ionViewDidLoad(){
  this.checkNewNotification().subscribe(()=>{
    this.events.publish("new-notification");
  })
}

Headercomponent

constructor( public cd: ChangeDetectorRef)
ngOnInit(){
  this.events.subscribe('new-notification', () => {
    console.log(cd);
    this.cd.detectChanges();
})
}

When I login from WelcomePage to HomePage and “new-notification” event is fired, the HeaderComponent fires this.cd.detectChanges() . But for some reason this throws ViewDestroyedError .And the error description mentiones welcome.html. And when I log cd , the destroyed attribute is true .

So my question is why does the ChangeDetectionRef injected in HeaderComponent trying to detect changes in WelcomePage ?

Edit

I tried markForChanges , and it works. Not sure why?

Posts: 1

Participants: 1

Read full topic


Viewing all articles
Browse latest Browse all 71531

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>