@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'); }) }
TabPagehas aHomePagewhich hasHeaderComponentHomePage 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
WelcomePagetoHomePageand “new-notification” event is fired, theHeaderComponentfiresthis.cd.detectChanges(). But for some reason this throwsViewDestroyedError.And the error description mentioneswelcome.html. And when I logcd, thedestroyedattribute istrue.So my question is why does the
ChangeDetectionRefinjected inHeaderComponenttrying to detect changes inWelcomePage?Edit
I tried
markForChanges, and it works. Not sure why?
Posts: 1
Participants: 1