Skip to content

Commit

Permalink
feat(platform): create platform with bootstrap fn helper
Browse files Browse the repository at this point in the history
  • Loading branch information
Hotell committed Jan 10, 2016
1 parent ef16937 commit 402c5c8
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
1 change: 1 addition & 0 deletions platform.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './src/platform/browser';
34 changes: 34 additions & 0 deletions src/platform/browser.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
export type AppRoot = string | Element | Document;

/**
* bootstrap angular app
* @param {ng.IModule} ngModule
* @param {string | Element | Document} [element=document]
* @param {boolean} [strictDi=true]
*/
export function bootstrap(
ngModule: ng.IModule,
{element=document,strictDi=true}: {
element?: AppRoot,
strictDi?: boolean
}={}
) {

const appRoot = _getAppRoot( element );

angular.element( document ).ready( ()=> {
angular.bootstrap( appRoot, [ ngModule.name ], {
strictDi: true
} )
} );

}

function _getAppRoot( element: AppRoot ): Element {

if ( typeof element === 'string' ) {
return document.querySelector( element );
}
return element as Element;

}

0 comments on commit 402c5c8

Please sign in to comment.