mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2026-03-13 10:22:08 +08:00
feat(Registry)
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
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 {NavPage} from './pages/nav'
|
||||
@@ -22,7 +22,8 @@ import {ModalPage} from './pages/modal'
|
||||
selector: 'ion-app',
|
||||
})
|
||||
@IonicView({
|
||||
templateUrl: 'main.html'
|
||||
templateUrl: 'main.html',
|
||||
directives: [Register]
|
||||
})
|
||||
class IonicApp {
|
||||
constructor() {
|
||||
@@ -49,7 +50,8 @@ class IonicApp {
|
||||
openPage(aside, component) {
|
||||
aside.close();
|
||||
|
||||
window.nav.setItems([component.component]);
|
||||
let nav = Registry.get('myNav');
|
||||
nav.setItems([component.component]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
</ion-content>
|
||||
</ion-aside>
|
||||
|
||||
<ion-nav #content [root]="rootView"></ion-nav>
|
||||
<ion-nav #content [root]="rootView" [register]="content" register-id="myNav"></ion-nav>
|
||||
|
||||
<style>
|
||||
my-modal {
|
||||
|
||||
@@ -43,7 +43,6 @@ import {Routable, NavbarTemplate, Navbar, NavController, Content} from 'ionic/io
|
||||
export class ButtonPage {
|
||||
constructor(nav: NavController) {
|
||||
this.nav = nav;
|
||||
window.nav = nav;
|
||||
}
|
||||
|
||||
onButtonClick(event) {
|
||||
|
||||
@@ -7,7 +7,6 @@ import {FormBuilder, Validators, formDirectives, ControlGroup} from 'angular2/fo
|
||||
import {Segment, SegmentButton, SearchBar, List, Item, ActionMenu, Modal, ModalRef,
|
||||
NavbarTemplate, Navbar, NavController, Content} from 'ionic/ionic';
|
||||
|
||||
console.log(NavbarTemplate, Navbar, Content, formDirectives);
|
||||
|
||||
@Component({
|
||||
selector: 'ion-view',
|
||||
|
||||
@@ -3,6 +3,8 @@ export * from 'ionic/config/config'
|
||||
export * from 'ionic/config/component'
|
||||
export * from 'ionic/config/ionic-view'
|
||||
|
||||
export * from 'ionic/registry'
|
||||
|
||||
export * from 'ionic/components'
|
||||
|
||||
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