diff --git a/ionic/components/nav/test/button/index.ts b/ionic/components/nav/test/button/index.ts new file mode 100644 index 0000000000..23a3813d1f --- /dev/null +++ b/ionic/components/nav/test/button/index.ts @@ -0,0 +1,41 @@ +import {Query, ViewQuery, QueryList, bootstrap, ElementRef, Component, Directive, View, Injectable, Renderer} from 'angular2/angular2'; + + +@Component({ + selector: 'icon' +}) +@View({ + template: '♠' +}) +class Icon {} + + +@Directive({ + selector: 'button' +}) +class Button { + constructor(@Query(Icon) public icon: QueryList) { + icon.onChange( ()=> { + console.log('button icon', icon); + }); + } + onInit() { + console.log('Button icon', this.icon); + } +} + +@Component({ + selector: 'ion-app' +}) +@View({ + template: ` + + `, + directives: [Button, Icon] +}) +export class HelloCmp { + +} + + +bootstrap(HelloCmp); diff --git a/ionic/components/nav/test/user-app/index.ts b/ionic/components/nav/test/user-app/index.ts new file mode 100644 index 0000000000..bd9b98069e --- /dev/null +++ b/ionic/components/nav/test/user-app/index.ts @@ -0,0 +1,144 @@ +import { + Directive, + Component, + View, + bootstrap, + Injectable, + Inject, + Ancestor, + forwardRef, + Inject, + DynamicComponentLoader, + ElementRef, + Query, + QueryList, + ComponentRef + } from 'angular2/angular2'; + + +@Injectable() +class IonicModal { + constructor() { + console.log('IonicModal constructor'); + } + open(componentType) { + console.log('IonicModal open:', componentType.name); + } +} + +@Injectable() +class UserService { + constructor() { + console.log('UserService constructor'); + this.id = Math.random(); + } +} + +@Directive({ + selector: 'button', + host: { + 'ionic-button': 'true' + } +}) +class IonicButton { + constructor() { + console.log('IonicButton') + } +} + +@Directive({ + selector: 'button', + host: { + 'user-button': 'true' + } +}) +class UserButton { + constructor() { + console.log('UserButton') + } +} + +var IonicDirectives = [IonicButton]; + +@Component({ + selector: 'user-modal' +}) +@View({ + template: ` +
+

user modal

+

UserService: {{userService.id}} +

+ ` +}) +class UserModal { + constructor(userService: UserService) { + console.log('UserModal constructor'); + this.userService = userService; + } +} + + + +@Component({ + selector: 'user-app', + hostInjector: [UserService] +}) +@View({ + template: ` +

user root component

+ + + `, + directives: IonicDirectives.concat([UserButton]) +}) +class UserRootComponent { + constructor(ionicModal: IonicModal, userService: UserService) { + console.log('UserRootComponent constructor'); + this.ionicModal = ionicModal; + } + openModal(){ + this.ionicModal.open(UserModal); + } +} + + +@Directive({ + selector: 'overlay-anchor' +}) +class OverlayAnchor { + constructor( + userService: UserService, + public elementRef: ElementRef, + loader: DynamicComponentLoader) + { + console.log('OverlayAnchor constructor', userService); + loader.loadNextToLocation(UserModal, elementRef).then((ref: ComponentRef) => { + }); + } +} + + + +function ionicApp(userApp: Type) { + function IonicRootComponent() {} + IonicRootComponent.annotations = [ + new Component({ + selector: 'ion-app', + viewInjector: [IonicModal] + }), + new View({ + template: ` + + + `, + directives: [userApp, OverlayAnchor] + }) + ]; + return IonicRootComponent; +} + +console.log('bootstrap') +bootstrap(ionicApp(UserRootComponent)).catch(err => { + console.error('bootstrap', err); +});