import { Directive, Component, View, bootstrap, Injectable, Inject, 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 IONIC_DIRECTIVES = [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: IONIC_DIRECTIVES.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); });