angular - Use JSON url to navigate/push to page -


i working on ionic2 app. have json file using , want set type or url param can use each element in list, navigate specific page in ionic2. tried like: [navpush]="{{ data.url }}" not work. tried like: (click)="gotopage({{data.url}})" not work either.

i want able set page want navigate dynamically (read json), instead using separate functions each item in list

like:

gotopage() {     this.nav.push(pagetonavigateto);   } 

ionic provides example this. create new project this: ionic start name sidemenu (or manually select template sidemenu).

in app.component.ts find example json array pages , function called openpage(). can use own project.

or can right here, in github repository.

if want use strings page navigation, need lazy load pages. here quick tutorial on how lazy load page:

  1. remove page declarations , imports app.module.ts , app.component.ts.
  2. you need create module.ts every page have (for example home.module.ts). this:

home.module.ts

import { ngmodule } '@angular/core'; import { ionicpagemodule } 'ionic-angular'; import { homepage } './home';  @ngmodule({   declarations: [     homepage   ],   imports: [     ionicpagemodule.forchild(homepage)   ],   exports: [     homepage   ] })  export class homemodule {} 
  1. now ready go, change rootpage:any = homepage rootpage:string = 'homepage in app.component.ts

now can use function openpage() navigate through app:

public openpage (name: string) : void {   this.nav.setroot(name); } 

Comments

Popular posts from this blog

node.js - Node js - Trying to send POST request, but it is not loading javascript content -

javascript - Replicate keyboard event with html button -

javascript - Web audio api 5.1 surround example not working in firefox -