mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2025-08-22 21:48:42 +08:00
fix(navParams): move navParams to nav-params.ts
This commit is contained in:
@ -1,11 +1,11 @@
|
|||||||
import {Component, Renderer, ElementRef} from 'angular2/core';
|
import {Component, Renderer, ElementRef} from 'angular2/core';
|
||||||
import {NgFor, NgIf} from 'angular2/common';
|
import {NgFor, NgIf} from 'angular2/common';
|
||||||
|
|
||||||
import {NavParams} from '../nav/nav-controller';
|
import {Animation} from '../../animations/animation';
|
||||||
import {ViewController} from '../nav/view-controller';
|
|
||||||
import {Config} from '../../config/config';
|
import {Config} from '../../config/config';
|
||||||
import {Icon} from '../icon/icon';
|
import {Icon} from '../icon/icon';
|
||||||
import {Animation} from '../../animations/animation';
|
import {NavParams} from '../nav/nav-params';
|
||||||
|
import {ViewController} from '../nav/view-controller';
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1,11 +1,11 @@
|
|||||||
import {Component, ElementRef, Renderer} from 'angular2/core';
|
import {Component, ElementRef, Renderer} from 'angular2/core';
|
||||||
import {NgClass, NgSwitch, NgIf, NgFor} from 'angular2/common';
|
import {NgClass, NgSwitch, NgIf, NgFor} from 'angular2/common';
|
||||||
|
|
||||||
import {NavParams} from '../nav/nav-controller';
|
|
||||||
import {ViewController} from '../nav/view-controller';
|
|
||||||
import {Config} from '../../config/config';
|
|
||||||
import {Animation} from '../../animations/animation';
|
import {Animation} from '../../animations/animation';
|
||||||
|
import {Config} from '../../config/config';
|
||||||
import {isDefined} from '../../util/util';
|
import {isDefined} from '../../util/util';
|
||||||
|
import {NavParams} from '../nav/nav-params';
|
||||||
|
import {ViewController} from '../nav/view-controller';
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1,15 +1,16 @@
|
|||||||
import {Compiler, ElementRef, Injector, provide, NgZone, AppViewManager, Renderer, ResolvedProvider, Type} from 'angular2/core';
|
import {Compiler, ElementRef, Injector, provide, NgZone, AppViewManager, Renderer, ResolvedProvider, Type} from 'angular2/core';
|
||||||
import {wtfLeave, wtfCreateScope, WtfScopeFn, wtfStartTimeRange, wtfEndTimeRange} from 'angular2/instrumentation';
|
import {wtfLeave, wtfCreateScope, WtfScopeFn, wtfStartTimeRange, wtfEndTimeRange} from 'angular2/instrumentation';
|
||||||
|
|
||||||
|
import {Animation} from '../../animations/animation';
|
||||||
|
import {Config} from '../../config/config';
|
||||||
import {Ion} from '../ion';
|
import {Ion} from '../ion';
|
||||||
import {IonicApp} from '../app/app';
|
import {IonicApp} from '../app/app';
|
||||||
import {Config} from '../../config/config';
|
|
||||||
import {Keyboard} from '../../util/keyboard';
|
|
||||||
import {ViewController} from './view-controller';
|
|
||||||
import {Animation} from '../../animations/animation';
|
|
||||||
import {SwipeBackGesture} from './swipe-back';
|
|
||||||
import {isBoolean, array, pascalCaseToDashCase} from '../../util/util';
|
import {isBoolean, array, pascalCaseToDashCase} from '../../util/util';
|
||||||
|
import {Keyboard} from '../../util/keyboard';
|
||||||
|
import {NavParams} from './nav-params';
|
||||||
import {raf, rafFrames} from '../../util/dom';
|
import {raf, rafFrames} from '../../util/dom';
|
||||||
|
import {SwipeBackGesture} from './swipe-back';
|
||||||
|
import {ViewController} from './view-controller';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* _For examples on the basic usage of NavController, check out the
|
* _For examples on the basic usage of NavController, check out the
|
||||||
@ -1496,70 +1497,18 @@ export class NavController extends Ion {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const STATE_ACTIVE = 1;
|
export const STATE_ABORT = -1;
|
||||||
const STATE_INACTIVE = 2;
|
export const STATE_ACTIVE = 1;
|
||||||
const STATE_INIT_ENTER = 3;
|
export const STATE_INACTIVE = 2;
|
||||||
const STATE_INIT_LEAVE = 4;
|
export const STATE_INIT_ENTER = 3;
|
||||||
const STATE_RENDER_ENTER = 5;
|
export const STATE_INIT_LEAVE = 4;
|
||||||
const STATE_RENDER_LEAVE = 6;
|
export const STATE_RENDER_ENTER = 5;
|
||||||
const STATE_POST_RENDER_ENTER = 7;
|
export const STATE_RENDER_LEAVE = 6;
|
||||||
const STATE_POST_RENDER_LEAVE = 8;
|
export const STATE_POST_RENDER_ENTER = 7;
|
||||||
const STATE_BEFORE_TRANS_ENTER = 9;
|
export const STATE_POST_RENDER_LEAVE = 8;
|
||||||
const STATE_BEFORE_TRANS_LEAVE = 10;
|
export const STATE_BEFORE_TRANS_ENTER = 9;
|
||||||
const STATE_AFTER_TRANS_ENTER = 11;
|
export const STATE_BEFORE_TRANS_LEAVE = 10;
|
||||||
const STATE_AFTER_TRANS_LEAVE = 12;
|
export const STATE_AFTER_TRANS_ENTER = 11;
|
||||||
|
export const STATE_AFTER_TRANS_LEAVE = 12;
|
||||||
|
|
||||||
let ctrlIds = -1;
|
let ctrlIds = -1;
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @name NavParams
|
|
||||||
* @description
|
|
||||||
* NavParams are an object that exists on a page and can contain data for that particular view.
|
|
||||||
* Similar to how data was pass to a view in V1 with `$stateParams`, NavParams offer a much more flexible
|
|
||||||
* option with a simple `get` method.
|
|
||||||
*
|
|
||||||
* @usage
|
|
||||||
* ```ts
|
|
||||||
* export class MyClass{
|
|
||||||
* constructor(params: NavParams){
|
|
||||||
* this.params = params;
|
|
||||||
* // userParams is an object we have in our nav-parameters
|
|
||||||
* this.params.get('userParams');
|
|
||||||
* }
|
|
||||||
* }
|
|
||||||
* ```
|
|
||||||
* @demo /docs/v2/demos/nav-params/
|
|
||||||
* @see {@link /docs/v2/components#navigation Navigation Component Docs}
|
|
||||||
* @see {@link ../NavController/ NavController API Docs}
|
|
||||||
* @see {@link ../Nav/ Nav API Docs}
|
|
||||||
* @see {@link ../NavPush/ NavPush API Docs}
|
|
||||||
*/
|
|
||||||
export class NavParams {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @private
|
|
||||||
* @param {TODO} data TODO
|
|
||||||
*/
|
|
||||||
constructor(public data: any = {}) {}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the value of a nav-parameter for the current view
|
|
||||||
*
|
|
||||||
* ```ts
|
|
||||||
* export class MyClass{
|
|
||||||
* constructor(params: NavParams){
|
|
||||||
* this.params = params;
|
|
||||||
* // userParams is an object we have in our nav-parameters
|
|
||||||
* this.params.get('userParams');
|
|
||||||
* }
|
|
||||||
* }
|
|
||||||
* ```
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* @param {string} parameter Which param you want to look up
|
|
||||||
*/
|
|
||||||
get(param: string): any {
|
|
||||||
return this.data[param];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
54
ionic/components/nav/nav-params.ts
Normal file
54
ionic/components/nav/nav-params.ts
Normal file
@ -0,0 +1,54 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @name NavParams
|
||||||
|
* @description
|
||||||
|
* NavParams are an object that exists on a page and can contain data for that particular view.
|
||||||
|
* Similar to how data was pass to a view in V1 with `$stateParams`, NavParams offer a much more flexible
|
||||||
|
* option with a simple `get` method.
|
||||||
|
*
|
||||||
|
* @usage
|
||||||
|
* ```ts
|
||||||
|
* export class MyClass{
|
||||||
|
* constructor(params: NavParams){
|
||||||
|
* this.params = params;
|
||||||
|
* // userParams is an object we have in our nav-parameters
|
||||||
|
* this.params.get('userParams');
|
||||||
|
* }
|
||||||
|
* }
|
||||||
|
* ```
|
||||||
|
* @demo /docs/v2/demos/nav-params/
|
||||||
|
* @see {@link /docs/v2/components#navigation Navigation Component Docs}
|
||||||
|
* @see {@link ../NavController/ NavController API Docs}
|
||||||
|
* @see {@link ../Nav/ Nav API Docs}
|
||||||
|
* @see {@link ../NavPush/ NavPush API Docs}
|
||||||
|
*/
|
||||||
|
export class NavParams {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @private
|
||||||
|
* @param {TODO} data TODO
|
||||||
|
*/
|
||||||
|
constructor(public data: any = {}) {}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the value of a nav-parameter for the current view
|
||||||
|
*
|
||||||
|
* ```ts
|
||||||
|
* export class MyClass{
|
||||||
|
* constructor(params: NavParams){
|
||||||
|
* this.params = params;
|
||||||
|
* // userParams is an object we have in our nav-parameters
|
||||||
|
* this.params.get('userParams');
|
||||||
|
* }
|
||||||
|
* }
|
||||||
|
* ```
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @param {string} parameter Which param you want to look up
|
||||||
|
*/
|
||||||
|
get(param: string): any {
|
||||||
|
return this.data[param];
|
||||||
|
}
|
||||||
|
}
|
@ -45,7 +45,7 @@ export class NavRouter extends RouterOutlet {
|
|||||||
|
|
||||||
// prevent double navigations to the same view
|
// prevent double navigations to the same view
|
||||||
var lastView = this._nav.last();
|
var lastView = this._nav.last();
|
||||||
if (this._nav.isTransitioning() || lastView && lastView.componentType === componentType && lastView.params.data === nextInstruction.params) {
|
if (this._nav.isTransitioning() || lastView && lastView.componentType === componentType && lastView.data === nextInstruction.params) {
|
||||||
return Promise.resolve();
|
return Promise.resolve();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -199,6 +199,15 @@ export function run() {
|
|||||||
expect(nav._views[5].componentType).toBe(FirstPage);
|
expect(nav._views[5].componentType).toBe(FirstPage);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('another insert happened before last insert rendered, abort previous insert enter', () => {
|
||||||
|
let view1 = new ViewController();
|
||||||
|
view1._loaded = true;
|
||||||
|
view1.state = NavController.STATE_ABORT;
|
||||||
|
let view2 = new ViewController();
|
||||||
|
view2._loaded = true;
|
||||||
|
nav._views = [view1, view2];
|
||||||
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("setRoot", () => {
|
describe("setRoot", () => {
|
||||||
|
@ -1,6 +1,9 @@
|
|||||||
import {Output, EventEmitter, Type, TemplateRef, ViewContainerRef, ElementRef} from 'angular2/core';
|
import {Output, EventEmitter, Type, TemplateRef, ViewContainerRef, ElementRef} from 'angular2/core';
|
||||||
import {NavController, NavParams} from './nav-controller';
|
|
||||||
import {Navbar} from '../navbar/navbar';
|
import {Navbar} from '../navbar/navbar';
|
||||||
|
import {NavController} from './nav-controller';
|
||||||
|
import {NavParams} from './nav-params';
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @name ViewController
|
* @name ViewController
|
||||||
|
Reference in New Issue
Block a user