diff --git a/ionic/components.ts b/ionic/components.ts index 53cbbc7903..b43f20bac9 100644 --- a/ionic/components.ts +++ b/ionic/components.ts @@ -3,6 +3,7 @@ export * from 'ionic/components/app/app' export * from 'ionic/components/app/register' export * from 'ionic/components/action-menu/action-menu' export * from 'ionic/components/aside/aside' +export * from 'ionic/components/aside/aside-toggle' export * from 'ionic/components/button/button' export * from 'ionic/components/card/card' export * from 'ionic/components/checkbox/checkbox' diff --git a/ionic/components/app/app.ts b/ionic/components/app/app.ts index 63986448ce..ce4f1615e8 100644 --- a/ionic/components/app/app.ts +++ b/ionic/components/app/app.ts @@ -60,6 +60,21 @@ export class IonicApp { // TODO(mlynch): We need to track the lifecycle of this component to remove it onDehydrate } + /** + * Unregister a known component with a key. + */ + unregister(key, component) { + delete this.components[key]; + } + + getRegisteredComponent(cls) { + for(let component of this.components) { + if(component instanceof cls) { + return component; + } + } + } + /** * Get the component for the given key. */ diff --git a/ionic/components/app/register.ts b/ionic/components/app/register.ts index 27ec7151a7..5b25b57dd9 100644 --- a/ionic/components/app/register.ts +++ b/ionic/components/app/register.ts @@ -1,5 +1,6 @@ -import {Directive} from 'angular2/angular2'; +import {Directive, Self, Type} from 'angular2/angular2'; +import {Ion} from '../ion'; import {IonicApp} from './app'; @@ -26,3 +27,30 @@ export class Register { } } + + +@Directive({ + selector: '[ref]', + properties: [ + 'ref' + ], + host: { + 'this.ref': 'refId' + } +}) +export class Ref { + + constructor(app: IonicApp, @Self() component: any) { + this.app = app; + console.log('Register on any', component) + } + + onInit() { + /* + if (this.register && this.registerId) { + this.app.register(this.registerId, this.register); + } + */ + } + +} diff --git a/ionic/components/aside/aside-toggle.ts b/ionic/components/aside/aside-toggle.ts new file mode 100644 index 0000000000..30a6194333 --- /dev/null +++ b/ionic/components/aside/aside-toggle.ts @@ -0,0 +1,24 @@ +import {forwardRef, Component, Host, View, EventEmitter, ElementRef} from 'angular2/angular2'; + +import {Ion} from '../ion'; +import {IonicApp} from '../app/app'; +import {Button} from '../ion/components/button'; +import {IonicConfig} from '../../config/config'; +import {IonicDirective} from '../../config/annotations'; + +@IonicDirective({ + selector: '[aside-toggle]', + host: { + '(^click)': 'toggle($event)' + } +}) +export class AsideToggle { + constructor(app: IonicApp) { + //TODO(mlynch): don't hard code this, evaluate with ref system + this.aside = app.getComponent('menu'); + } + toggle(event) { + console.log('Toggling', this.aside) + this.aside && this.aside.toggle(); + } +} diff --git a/ionic/components/aside/aside.ts b/ionic/components/aside/aside.ts index 3a54c11978..f99be3a1b3 100644 --- a/ionic/components/aside/aside.ts +++ b/ionic/components/aside/aside.ts @@ -1,6 +1,7 @@ import {forwardRef, Component, Host, View, EventEmitter, ElementRef} from 'angular2/angular2'; import {Ion} from '../ion'; +import {IonicApp} from '../app/app'; import {IonicConfig} from '../../config/config'; import {IonicComponent} from '../../config/annotations'; import * as types from './extensions/types' @@ -42,9 +43,14 @@ import {dom} from 'ionic/util' }) export class Aside extends Ion { - constructor(elementRef: ElementRef, config: IonicConfig) { + constructor(app: IonicApp, elementRef: ElementRef, config: IonicConfig) { super(elementRef, config); + this.app = app; + + // TODO(mlynch): We need to build out the ref system + app.register('menu', this); + this.opening = new EventEmitter('opening'); // TODO: Use Animation Class @@ -53,6 +59,10 @@ export class Aside extends Ion { }) } + onDestroy() { + app.unregister(this); + } + onInit() { super.onInit(); this.contentElement = (this.content instanceof Node) ? this.content : this.content.getNativeElement(); diff --git a/ionic/components/aside/test/basic/home-page.html b/ionic/components/aside/test/basic/home-page.html index efecb84d9f..dfa20e5fb7 100644 --- a/ionic/components/aside/test/basic/home-page.html +++ b/ionic/components/aside/test/basic/home-page.html @@ -2,7 +2,7 @@ - @@ -18,7 +18,7 @@

Content

- +

diff --git a/ionic/components/aside/test/basic/index.ts b/ionic/components/aside/test/basic/index.ts index 43e5c8af7a..d7fdbe6f3b 100644 --- a/ionic/components/aside/test/basic/index.ts +++ b/ionic/components/aside/test/basic/index.ts @@ -5,16 +5,9 @@ import {App, IonicApp, IonicView, NavController} from 'ionic/ionic'; templateUrl: 'home-page.html' }) class HomePage { - constructor(app: IonicApp) { this.app = app; } - - toggleAside() { - console.log('toggleAside') - this.app.getComponent('mainMenu').toggle(); - } - } @@ -27,9 +20,4 @@ class E2EApp { this.app = app; this.rootView = HomePage; } - - closeMenu() { - this.app.getComponent('mainMenu').close(); - } - } diff --git a/ionic/components/aside/test/basic/main.html b/ionic/components/aside/test/basic/main.html index 2e9d2f4632..93e13e4a5d 100644 --- a/ionic/components/aside/test/basic/main.html +++ b/ionic/components/aside/test/basic/main.html @@ -1,5 +1,5 @@ - + Left Menu diff --git a/ionic/config/annotations.ts b/ionic/config/annotations.ts index 96863e72a3..d5ce2d142d 100644 --- a/ionic/config/annotations.ts +++ b/ionic/config/annotations.ts @@ -4,7 +4,7 @@ import * as util from 'ionic/util'; import {IonicConfig} from './config'; import {ionicBootstrap} from '../components/app/app'; import { - Aside, Button, Content, Scroll, Refresher, + Aside, AsideToggle, Button, Content, Scroll, Refresher, Slides, Slide, SlidePager, Tabs, Tab, Card, List, ListHeader, Item, ItemGroup, ItemGroupTitle, @@ -32,6 +32,8 @@ export const IonicDirectives = [ // Content forwardRef(() => Aside), + forwardRef(() => AsideToggle), + forwardRef(() => Button), forwardRef(() => Content), forwardRef(() => Scroll), @@ -79,6 +81,7 @@ export const IonicDirectives = [ forwardRef(() => NavPop), forwardRef(() => NavRouter), forwardRef(() => Register), + //forwardRef(() => Ref), forwardRef(() => ShowWhen), forwardRef(() => HideWhen),