Sy C Dang
Sy C Dang

Reputation: 53

ionic: Navigate from ionic page to root (HomePage)

I'm doing an ionic example: simple Notes app which let user add Note and display notes. When navigate from ionic page back to homepage I get this error: enter image description here

This is the simple app:

NOte list

When press ADD from homepage, New Ionic page is displayed.

enter image description here

After user type Title and Content, then press Add one note will be added to the list and then app navigate back to homepage. What I did is: - Create add-note page. - In add-note.ts, I navigate back to homepage like this:

addNote(note: Note){
this.noteListService.addNote(note).then(ref => {
  this.navCtrl.setRoot('HomePage');
});

}

I did tried this.navCtrl.popToRoot() but it not work.

Anybody know the reason?

Upvotes: 0

Views: 145

Answers (2)

Sy C Dang
Sy C Dang

Reputation: 53

After a while, I fix this problem by: - Import HomePage:

import { HomePage } from '../../pages/home/home'

  • setRoot(HomePage) instead of setRoot('HomePage'):

this.navCtrl.setRoot(HomePage);

Upvotes: 0

fastr.de
fastr.de

Reputation: 1523

the flow should something like this. The app starts and the HomePage is loaded and displayed as root. When you navigate to another page you do this.navCtrl.push(otherPage). When you want to go back to the root you do this.navCtrl.pop()

see Ionic NavController for further details.

Upvotes: 0

Related Questions