Failed to navigate between page in ionic v2


#1

hi i try to create a login page when pass the correct params it go to the home page i try hard but when it always show me a white page after the i serve dont show any page

here is my home.js code whiche have the form of the login:

import {Page} from 'ionic-angular';
import {Page, NavController} from 'ionic-angular';
import {MenuhomePage} from '../menuhome/menuhome';

@Page({
    templateUrl: 'build/pages/home/home.html'
})
export class HomePage {
  constructor(nav: NavController) {
      this.nav = nav;
  }

  goToMenuHome(){
      this.nav.push(MenuhomePage);
  }
}

and here how i call it from the html folder inside a button tag:

<button (click)="goToMenuHome()">

Any help please…
Thank in advance


#2

You mentioned home.js so I guess that you’re using JavaScript and not TypeScript. In this case you cannot use the type annotations since they are invalid syntax in JavaScript. Therefore you should use static get parameters() for dependency injection, i.e. update your code this way:

import {Page, NavController} from 'ionic-angular';
import {MenuhomePage} from '../menuhome/menuhome';

@Page({
    templateUrl: 'build/pages/home/home.html'
})
export class HomePage {
  static get parameters() {
      return [[NavController]];
  }

  constructor(nav) {
      this.nav = nav;
  }

  goToMenuHome() {
      this.nav.push(MenuhomePage);
  }
}

#3

okay thank you so much it work correctly :relaxed:


#4

Ok, great, I’m glad you got it working. :slight_smile: