Reputation: 586
I just want to check current page name in Ionic 2 for that I have used NavController in app.component.ts, but this giving an error that No provider for NavController. Please suggest me some solution, Thanks in advance.
This is My Code below :
constructor(platform: Platform,public alertCtrl: AlertController,public navControll:NavController) {
this.platform=platform;
//this.nav=nav;
platform.ready().then(()=>{
if(navControll.canGoBack())
{
platform.registerBackButtonAction(()=>this.myHandlerFunction());
}
StatusBar.styleDefault();
Splashscreen.hide();
})
}
Upvotes: 4
Views: 7171
Reputation: 1883
In app.component you do not need to import NavController, because you have:
@ViewChild(Nav) nav: Nav;
instead you can try this:
this.nav
in other components:
import { NavController } from 'ionic-angular';
export class Page {
constructor(
public navController: NavController
) {}
}
this.navController
to see what you can do with NavController check this link. I think you must work with page index not page name.
Upvotes: 3
Reputation: 6421
You can use the navControll.canGoBack()
method.
It'll return true if there's a page to go back, so if it returns false it's in the root.
Upvotes: 9