Skip to content

Instantly share code, notes, and snippets.

@behnamazimi
Last active October 21, 2016 20:39
Show Gist options
  • Save behnamazimi/3a14ebbbd26e08483413b449884cf9cf to your computer and use it in GitHub Desktop.
Save behnamazimi/3a14ebbbd26e08483413b449884cf9cf to your computer and use it in GitHub Desktop.
Navigation in Ionic 2
this.navCtrl.push(Details);
import { NavParams } from 'ionic-angular';
@Component({
  templateUrl:’details.html’
})
class Details {
  constructor(private navParams: NavParams) {
     let username = navParams.get('username');
     let email = navParams.get('email');
  }
}
this.navCtrl.pop();
import { Component } from `@angular/core`;
import { ionicBootstrap } from 'ionic-angular';
import { StartPage } from './start-page';
@Component(
  template: `<ion-nav [root]="rootPage"></ion-nav>`
})
class MyApp {
  // set the rootPage to the first page we want displayed
  private rootPage: any = StartPage;
  constructor(){ }
}
ionicBootstrap(MyApp);
import { NavController } from 'ionic-angular';
insert(insertIndex, page, params, opts, done)
class MyComponent {
  constructor(public navCtrl: NavController) { }
}
import { App, ViewChild } from '@angular/core';
import { NavController } from 'ionic-angular';
import { Details } from './details';
@App({
   template: '<ion-nav #myNav [root]="rootPage"></ion-nav>'
})
export class MyApp {
   @ViewChild('myNav') nav: NavController
   private rootPage = OtherPage;
   ngAfterViewInit() {
      this.nav.push(Details);
   }
}
import { Details } from './details;
@Component({
  template: `<button ion-button [navPush]="pushPage" [navParams]="params">Go</button>`
})
class MyPage {
  constructor(){
    this.pushPage = Details;
    this.params = { username: “bhnmzm”, email:”example@mail.com”  };
  }
}
<button ion-button navPop></button>
<button ion-button [navPush]="pushPage"></button>
pop(params, opts, done);
popToRoot(opts, done)
this.navCtrl.push(Details, { username: “bhnmzm”, email:”example@mail.com” });
push(page, params, opts, done);
remove(startIndex, removeCount, opts)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment