diff --git a/ionic/components.ts b/ionic/components.ts index b43f20bac9..7d0e81d1d7 100644 --- a/ionic/components.ts +++ b/ionic/components.ts @@ -1,6 +1,6 @@ export * from 'ionic/components/app/app' -export * from 'ionic/components/app/register' +export * from 'ionic/components/app/id' export * from 'ionic/components/action-menu/action-menu' export * from 'ionic/components/aside/aside' export * from 'ionic/components/aside/aside-toggle' diff --git a/ionic/components/app/app.ts b/ionic/components/app/app.ts index 050933c421..3514329347 100644 --- a/ionic/components/app/app.ts +++ b/ionic/components/app/app.ts @@ -85,27 +85,27 @@ export class IonicApp { /** * Register a known component with a key, for easy lookups later. - * @param {TODO} key TODO - * @param {TODO} component TODO + * @param {TODO} key The key to use to register the component + * @param {TODO} component The component to register */ register(key, component) { this.components[key] = component; + console.log('Registered', key, component); // TODO(mlynch): We need to track the lifecycle of this component to remove it onDehydrate } /** * Unregister a known component with a key. - * @param {TODO} key TODO - * @param {TODO} component TODO + * @param {TODO} key The key to use to unregister */ - unregister(key, component) { + unregister(key) { delete this.components[key]; } /** - * TODO - * @param {Object} cls TODO - * @return TODO + * Get a registered component with the given type (returns the first) + * @param {Object} cls the type to search for + * @return the matching component, or undefined if none was found */ getRegisteredComponent(cls) { for(let component of this.components) { diff --git a/ionic/components/app/id.ts b/ionic/components/app/id.ts new file mode 100644 index 0000000000..e2b7d96a75 --- /dev/null +++ b/ionic/components/app/id.ts @@ -0,0 +1,31 @@ +import {AppViewManager, ElementRef, Directive, Self, Type} from 'angular2/angular2'; + +import {Ion} from '../ion'; +import {IonicApp} from './app'; + +/** + * IdRef is an easy way to identify unique components in an app and access them + * no matter where in the UI heirarchy you are. For example, this makes toggling + * a global side menu feasible from any place in the application. + */ +@Directive({ + selector: '[id]', + properties: ['id'] +}) +export class IdRef { + + constructor(private app: IonicApp, private elementRef: ElementRef, private appViewManager: AppViewManager) { + + // Grab the component this directive is attached to + this.component = appViewManager.getComponent(elementRef); + + } + + onInit() { + this.app.register(this.id, this.component); + } + + onDestroy() { + this.app.unregister(this.id); + } +} diff --git a/ionic/components/app/test/material/index.ts b/ionic/components/app/test/material/index.ts index 790da398b2..cb5cc5414e 100644 --- a/ionic/components/app/test/material/index.ts +++ b/ionic/components/app/test/material/index.ts @@ -6,7 +6,7 @@ import {App, ActionMenu, IonicApp, IonicView, Register} from 'ionic/ionic'; template: '' + 'Heading' + '' + - '' + + '' + '' + '' + '' + @@ -52,10 +52,6 @@ export class FirstPage { this.app = app; this.actionMenu = actionMenu; } - toggleMenu() { - console.log('TOGGLE'); - this.app.getComponent('myAside').toggle(); - } showMoreMenu() { this.actionMenu.open({ buttons: [ @@ -85,7 +81,7 @@ export class FirstPage { @App({ template: ` - + Menu Your Profile diff --git a/ionic/components/app/test/sink/index.ts b/ionic/components/app/test/sink/index.ts index f3e6142d54..aea31a0d36 100644 --- a/ionic/components/app/test/sink/index.ts +++ b/ionic/components/app/test/sink/index.ts @@ -94,14 +94,12 @@ class MyApp { { title: 'Slides', component: SlidePage}, { title: 'Action Menu', component: ActionMenuPage }, ]; - - //this.rootView = ButtonPage } openPage(aside, component) { aside.close(); let nav = this.app.getComponent('myNav'); - nav.setRoot(component.component); + nav.setItems([component.component]); } } diff --git a/ionic/components/app/test/sink/main.html b/ionic/components/app/test/sink/main.html index 145d90cb28..14bde37d3d 100644 --- a/ionic/components/app/test/sink/main.html +++ b/ionic/components/app/test/sink/main.html @@ -1,4 +1,4 @@ - + Ionic 2.0 @@ -9,7 +9,7 @@ - +