mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2025-08-20 12:29:55 +08:00
feat(Registry)
This commit is contained in:
@ -1,6 +1,6 @@
|
|||||||
import {Component, Directive} from 'angular2/src/core/annotations_impl/annotations';
|
import {Component, Directive} from 'angular2/src/core/annotations_impl/annotations';
|
||||||
|
|
||||||
import {IonicView} from 'ionic/ionic';
|
import {IonicView, Register, Registry} from 'ionic/ionic';
|
||||||
|
|
||||||
import {ButtonPage} from './pages/button'
|
import {ButtonPage} from './pages/button'
|
||||||
import {NavPage} from './pages/nav'
|
import {NavPage} from './pages/nav'
|
||||||
@ -22,7 +22,8 @@ import {ModalPage} from './pages/modal'
|
|||||||
selector: 'ion-app',
|
selector: 'ion-app',
|
||||||
})
|
})
|
||||||
@IonicView({
|
@IonicView({
|
||||||
templateUrl: 'main.html'
|
templateUrl: 'main.html',
|
||||||
|
directives: [Register]
|
||||||
})
|
})
|
||||||
class IonicApp {
|
class IonicApp {
|
||||||
constructor() {
|
constructor() {
|
||||||
@ -49,7 +50,8 @@ class IonicApp {
|
|||||||
openPage(aside, component) {
|
openPage(aside, component) {
|
||||||
aside.close();
|
aside.close();
|
||||||
|
|
||||||
window.nav.setItems([component.component]);
|
let nav = Registry.get('myNav');
|
||||||
|
nav.setItems([component.component]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -11,7 +11,7 @@
|
|||||||
</ion-content>
|
</ion-content>
|
||||||
</ion-aside>
|
</ion-aside>
|
||||||
|
|
||||||
<ion-nav #content [root]="rootView"></ion-nav>
|
<ion-nav #content [root]="rootView" [register]="content" register-id="myNav"></ion-nav>
|
||||||
|
|
||||||
<style>
|
<style>
|
||||||
my-modal {
|
my-modal {
|
||||||
|
@ -43,7 +43,6 @@ import {Routable, NavbarTemplate, Navbar, NavController, Content} from 'ionic/io
|
|||||||
export class ButtonPage {
|
export class ButtonPage {
|
||||||
constructor(nav: NavController) {
|
constructor(nav: NavController) {
|
||||||
this.nav = nav;
|
this.nav = nav;
|
||||||
window.nav = nav;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
onButtonClick(event) {
|
onButtonClick(event) {
|
||||||
|
@ -7,7 +7,6 @@ import {FormBuilder, Validators, formDirectives, ControlGroup} from 'angular2/fo
|
|||||||
import {Segment, SegmentButton, SearchBar, List, Item, ActionMenu, Modal, ModalRef,
|
import {Segment, SegmentButton, SearchBar, List, Item, ActionMenu, Modal, ModalRef,
|
||||||
NavbarTemplate, Navbar, NavController, Content} from 'ionic/ionic';
|
NavbarTemplate, Navbar, NavController, Content} from 'ionic/ionic';
|
||||||
|
|
||||||
console.log(NavbarTemplate, Navbar, Content, formDirectives);
|
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'ion-view',
|
selector: 'ion-view',
|
||||||
|
@ -3,6 +3,8 @@ export * from 'ionic/config/config'
|
|||||||
export * from 'ionic/config/component'
|
export * from 'ionic/config/component'
|
||||||
export * from 'ionic/config/ionic-view'
|
export * from 'ionic/config/ionic-view'
|
||||||
|
|
||||||
|
export * from 'ionic/registry'
|
||||||
|
|
||||||
export * from 'ionic/components'
|
export * from 'ionic/components'
|
||||||
|
|
||||||
export * from 'ionic/platform/platform'
|
export * from 'ionic/platform/platform'
|
||||||
|
49
ionic/registry.js
Normal file
49
ionic/registry.js
Normal file
@ -0,0 +1,49 @@
|
|||||||
|
import {ElementRef, For, Parent, onInit} from 'angular2/angular2'
|
||||||
|
import {Component, Directive} from 'angular2/src/core/annotations_impl/annotations';
|
||||||
|
import {View} from 'angular2/src/core/annotations_impl/view';
|
||||||
|
import {Ancestor, Self} from 'angular2/src/core/annotations_impl/visibility';
|
||||||
|
import {Type} from 'angular2/src/facade/lang';
|
||||||
|
|
||||||
|
import {FormBuilder, Validators, FormDirectives, ControlGroup} from 'angular2/forms';
|
||||||
|
import {Log} from 'ionic/util'
|
||||||
|
|
||||||
|
import {ViewController, Nav} from 'ionic/ionic'
|
||||||
|
|
||||||
|
|
||||||
|
@Directive({
|
||||||
|
selector: '[register]',
|
||||||
|
properties: [
|
||||||
|
'register',
|
||||||
|
'registerId: register-id'
|
||||||
|
],
|
||||||
|
host: {
|
||||||
|
'[register-id]': 'registerId'
|
||||||
|
},
|
||||||
|
lifecycle: [onInit]
|
||||||
|
})
|
||||||
|
export class Register {
|
||||||
|
constructor() {
|
||||||
|
}
|
||||||
|
onInit() {
|
||||||
|
console.log('Register on init', this.register, this.registerId);
|
||||||
|
Registry.register(this.registerId, this.register);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class RegistryManager {
|
||||||
|
constructor() {
|
||||||
|
this.components = {};
|
||||||
|
}
|
||||||
|
register(key, component) {
|
||||||
|
this.components[key] = component;
|
||||||
|
console.log('Registered', this.components);
|
||||||
|
// TODO(mlynch): We need to track the lifecycle of this component to remove it
|
||||||
|
}
|
||||||
|
get(key) {
|
||||||
|
return this.components[key];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var Registry = new RegistryManager();
|
||||||
|
|
||||||
|
export {Registry};
|
Reference in New Issue
Block a user