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:
- remove page declarations , imports
app.module.ts,app.component.ts. - you need create
module.tsevery page have (for examplehome.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 {} - now ready go, change
rootpage:any = homepagerootpage:string = 'homepageinapp.component.ts
now can use function openpage() navigate through app:
public openpage (name: string) : void { this.nav.setroot(name); }
Comments
Post a Comment