mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2025-08-19 03:32:21 +08:00
32 lines
819 B
TypeScript
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);
|
|
}
|
|
}
|