How can I open a page when clicked on a button?


#1

I tried the following:

HTML:

<button (click)="openAddPage()">
  <ion-icon name="add"></ion-icon>
</button>

JS:

import {Page, NavController} from 'ionic-angular'
import {AddPage} from '../add/add'

@Page({
  templateUrl: 'build/pages/lamps/lamps.html'
})

export class LampsPage {
  constructor(nav: NavController) {
    this.nav = nav
  }

  openAddPage() {
    this.nav.push(AddPage)
  }
}

But when running ionic serve I get the following error:

SyntaxError: /path/to/app/pages/lamps/lamps.js: Unexpected token (9:17) while parsing file: /path/to/app/pages/lamps/lamps.js

#2

you’re using typescript syntax if I’m not mistaken.

nav: NavController

import {Page, NavController} from 'ionic-angular'
import {AddPage} from '../add/add'

@Page({
  templateUrl: 'build/pages/lamps/lamps.html'
})

export class LampsPage {

static get parameters() {
      return [[NavController]];
  }

  constructor(nav) {
    this.nav = nav
  }

  openAddPage() {
    this.nav.push(AddPage)
  }
}