feat(navPush): support array syntax or [nav-params] property

This commit is contained in:
Tim Lancina
2015-09-24 15:53:14 -06:00
parent 0c49c72e35
commit 7fe4b69b98
2 changed files with 9 additions and 15 deletions

View File

@ -7,7 +7,8 @@ import {NavController} from './nav-controller';
@Directive({ @Directive({
selector: '[nav-push]', selector: '[nav-push]',
properties: [ properties: [
'navInstructions: navPush' 'instruction: navPush',
'params: navParams'
], ],
host: { host: {
'(click)': 'onClick($event)', '(click)': 'onClick($event)',
@ -23,23 +24,15 @@ export class NavPush {
this.nav = nav; this.nav = nav;
} }
set navInstructions(instructions) { onClick(event) {
if (instructions instanceof Array) { if (this.instruction instanceof Array) {
if (instructions.length > 2) { if (this.instruction.length > 2) {
throw 'Too many [nav-push] arguments, expects [View, { params }]' throw 'Too many [nav-push] arguments, expects [View, { params }]'
} }
this.destination = instructions[0]; this.nav.push(this.instruction[0], this.instruction[1]);
this.navParams = instructions[1];
} else { } else {
this.destination = instructions; this.nav.push(this.instruction, this.params);
} }
//let annotations = Reflect.getMetadata('annotations', view);
// TODO check to make sure destination is a Component/IonicView?
}
onClick(event) {
this.nav.push(this.destination, this.navParams);
} }
} }

View File

@ -17,7 +17,8 @@ import {NavParams, NavController} from 'ionic/ionic';
'<ion-content padding>' + '<ion-content padding>' +
'<p>{{title}}</p>' + '<p>{{title}}</p>' +
'<p><button id="from1To2" primary (click)="push()">Push (Go to 2nd)</button></p>' + '<p><button id="from1To2" primary (click)="push()">Push (Go to 2nd)</button></p>' +
'<p><button [nav-push]="[pushPage, {id: 42}]">Push w/ nav-push (Go to 2nd)</button></p>' + '<p><button [nav-push]="[pushPage, {id: 42}]">Push w/ nav-push array (Go to 2nd)</button></p>' +
'<p><button [nav-push]="pushPage" [nav-params]="{id:40}">Push w/ nav-push and nav-params (Go to 2nd)</button></p>' +
'<p><button (click)="setViews()">setViews() (Go to 3rd, no history)</button></p>' + '<p><button (click)="setViews()">setViews() (Go to 3rd, no history)</button></p>' +
'<icon class="ion-ios-arrow-back"></icon>' + '<icon class="ion-ios-arrow-back"></icon>' +
'<f></f><f></f><f></f><f></f><f></f><f></f><f></f><f></f><f></f><f></f>' + '<f></f><f></f><f></f><f></f><f></f><f></f><f></f><f></f><f></f><f></f>' +