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();
})
}
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With