diff --git a/ionic/components/app/app.js b/ionic/components/app/app.js index f0c3875548..6c680206f2 100644 --- a/ionic/components/app/app.js +++ b/ionic/components/app/app.js @@ -13,6 +13,7 @@ import {bind} from 'angular2/di'; import {Injectable} from 'angular2/src/di/decorators'; import {ViewContainerRef} from 'angular2/src/core/compiler/view_container_ref'; +import {IonicConfig} from '../../config/config'; import {ViewController} from '../view/view-controller'; @@ -28,18 +29,26 @@ class IonicRootComponent extends ViewController { compiler: Compiler, elementRef: ElementRef, loader: DynamicComponentLoader, - injector: Injector + parentInjector: Injector ) { - super(null, compiler, elementRef, loader, injector); - - IonicRoot.component(this); + let injector = parentInjector; + let ComponentType = null; if (appModules.length) { - let appModule = appModules.shift(); - if (appModule.default) { - this.push(appModule.default); - } + ComponentType = appModules.shift(); + + injector = parentInjector.resolveAndCreateChild([ + bind(IonicConfig).toValue(ComponentType._config) + ]); } + + super(null, compiler, elementRef, loader, injector); + IonicRoot.component(this); + + if (ComponentType) { + this.push(ComponentType); + } + } } @@ -55,10 +64,21 @@ class PaneAnchor { let appModules = []; +export function ionicBootstrap(ComponentType, config) { + ComponentType._config = config || new IonicConfig(); + appModules.push(ComponentType); + bootstrap(IonicRootComponent); +} + export function load(app) { - if (app) { - appModules.push(app); - bootstrap(IonicRootComponent); + if (!app) { + console.error('Invalid app module'); + + } else if (!app.main) { + console.error('App module missing main()'); + + } else { + app.main(); } } diff --git a/ionic/components/nav/test/basic/index.js b/ionic/components/nav/test/basic/index.js index efe28b8d62..98387f85f6 100644 --- a/ionic/components/nav/test/basic/index.js +++ b/ionic/components/nav/test/basic/index.js @@ -1,7 +1,7 @@ -import {bootstrap, QueryList} from 'angular2/angular2' import {Component, Directive, onInit} from 'angular2/src/core/annotations_impl/annotations'; import {View} from 'angular2/src/core/annotations_impl/view'; +import {ionicBootstrap, IonicConfig} from 'ionic/ionic'; import {Nav, NavPush, NavPop, NavParams, Routable, Router, NavController, NavbarTemplate, Navbar, NavPush, Content} from 'ionic/ionic'; import {SecondPage} from './pages/second-page' @@ -24,19 +24,22 @@ import {SecondPage} from './pages/second-page' '' + '' + '

First Page: {{ val }}

' + - '

' + - '

' + + '

' + + '

' + '' + '' + '' + '
', directives: [NavbarTemplate, Navbar, NavPush, Content] }) -export default class FirstPage { +class FirstPage { constructor( - nav: NavController + nav: NavController, + myConfig: IonicConfig ) { + console.log('myConfig', myConfig); + // TODO: Shouldn't have to do this Router.setNavController(nav); @@ -98,3 +101,10 @@ export default class FirstPage { new Routable(FirstPage, { url: '/first-page' }) + + +export function main() { + let myConfig = new IonicConfig(); + + ionicBootstrap(FirstPage, myConfig); +} diff --git a/ionic/config/config.js b/ionic/config/config.js index 40ca9886c6..05e4e4f19b 100644 --- a/ionic/config/config.js +++ b/ionic/config/config.js @@ -2,4 +2,8 @@ export class IonicConfig { + constructor() { + this.canWe = true; + } + } diff --git a/ionic/ionic.js b/ionic/ionic.js index 42d56d5a0e..67e10172d0 100644 --- a/ionic/ionic.js +++ b/ionic/ionic.js @@ -1,5 +1,6 @@ export * from 'ionic/config/component' +export * from 'ionic/config/config' export * from 'ionic/components' export * from 'ionic/directives' export * from 'ionic/platform/platform'