Files
Max Lynch 715680ac3f Shieeet
2015-08-28 15:57:14 -05:00

32 lines
819 B
TypeScript

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);
}
}