mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2025-08-18 19:21:34 +08:00
Routing with lifecycles
This commit is contained in:
@ -1,12 +1,13 @@
|
||||
import {Component, Directive} from 'angular2/src/core/annotations_impl/annotations';
|
||||
import {Component, Directive, onInit} from 'angular2/src/core/annotations_impl/annotations';
|
||||
import {View} from 'angular2/src/core/annotations_impl/view';
|
||||
import {ObservableWrapper} from 'angular2/src/facade/async';
|
||||
|
||||
import {Routable, Router, NavController, NavbarTemplate, Navbar, NavPush, Content} from 'ionic/ionic';
|
||||
import {SecondPage} from './second-page';
|
||||
|
||||
|
||||
@Component({selector: 'ion-view'})
|
||||
@Component({
|
||||
selector: 'ion-view',
|
||||
lifecycle: [onInit]
|
||||
})
|
||||
@View({
|
||||
template: '' +
|
||||
'<ion-navbar *navbar>' +
|
||||
@ -36,22 +37,18 @@ export class FirstPage {
|
||||
this.nav = nav;
|
||||
this.val = Math.round(Math.random() * 8999) + 1000;
|
||||
|
||||
this.router = FirstPage.router.invoke(this);
|
||||
|
||||
this.pushPage = SecondPage;
|
||||
this.pushData = {
|
||||
id: 420
|
||||
}
|
||||
}
|
||||
|
||||
setTimeout(() => {
|
||||
console.log(this._viewDidEnter);
|
||||
ObservableWrapper.subscribe(this._viewDidEnter, () => {
|
||||
console.log('ENTERRRRR');
|
||||
});
|
||||
});
|
||||
onInit() {
|
||||
}
|
||||
|
||||
viewLoaded() {
|
||||
this.router = FirstPage.router.invoke(this);
|
||||
console.log('viewLoaded first page');
|
||||
}
|
||||
|
||||
@ -61,7 +58,6 @@ export class FirstPage {
|
||||
|
||||
viewDidEnter() {
|
||||
console.log('viewDidEnter first page');
|
||||
Router.emit(this.router.routeInfo.url);
|
||||
}
|
||||
|
||||
viewWillLeave() {
|
||||
|
@ -36,7 +36,6 @@ export class SecondPage {
|
||||
this.params = params;
|
||||
this.val = Math.round(Math.random() * 8999) + 1000;
|
||||
|
||||
this.router = SecondPage.router.invoke(this);
|
||||
|
||||
console.log('Second page params:', params);
|
||||
}
|
||||
@ -51,6 +50,7 @@ export class SecondPage {
|
||||
|
||||
viewLoaded() {
|
||||
console.log('viewLoaded second page');
|
||||
this.router = SecondPage.router.invoke(this);
|
||||
}
|
||||
|
||||
viewWillEnter() {
|
||||
@ -59,7 +59,6 @@ export class SecondPage {
|
||||
|
||||
viewDidEnter() {
|
||||
console.log('viewDidEnter second page');
|
||||
Router.emit(this.router.routeInfo.url);
|
||||
}
|
||||
|
||||
viewWillLeave() {
|
||||
|
@ -157,8 +157,10 @@ export class ViewItem {
|
||||
|
||||
setInstance(instance) {
|
||||
this.instance = instance;
|
||||
this.instance._viewItem = this;
|
||||
|
||||
this.instance._viewDidEnter = new EventEmitter('viewDidEnter');
|
||||
this.instance._viewWillEnter = new EventEmitter('viewWillEnter');
|
||||
}
|
||||
|
||||
cache() {
|
||||
@ -256,6 +258,7 @@ export class ViewItem {
|
||||
*/
|
||||
willEnter() {
|
||||
this.instance && this.instance.viewWillEnter && this.instance.viewWillEnter();
|
||||
this.instance && this.instance._viewWillEnter.next();
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -159,12 +159,19 @@ export class Routable {
|
||||
this.componentClass = componentClass;
|
||||
this.routeInfo = routeInfo;
|
||||
|
||||
console.log('New routable', componentClass, routeInfo);
|
||||
//console.log('New routable', componentClass, routeInfo);
|
||||
|
||||
componentClass.router = this;
|
||||
}
|
||||
invoke(componentInstance) {
|
||||
console.log('Routable invoke', componentInstance);
|
||||
// Called on viewLoaded
|
||||
|
||||
// Bind some lifecycle events
|
||||
componentInstance._viewWillEnter.observer({
|
||||
next: () => {
|
||||
Router.emit(this.routeInfo.url);
|
||||
}
|
||||
});
|
||||
|
||||
return this;
|
||||
}
|
||||
|
Reference in New Issue
Block a user