@@ -28,34 +28,72 @@ import {NS_DIRECTIVES} from './directives/ns-directives';
28
28
29
29
import { bootstrap as angularBootstrap } from 'angular2/bootstrap' ;
30
30
31
+ import { Page } from 'ui/page' ;
32
+ import { topmost } from 'ui/frame' ;
33
+ import { TextView } from 'ui/text-view' ;
34
+ import application = require( 'application' ) ;
35
+
31
36
export type ProviderArray = Array < Type | Provider | any [ ] > ;
32
37
33
- export function nativeScriptBootstrap ( appComponentType : any ,
34
- customProviders : ProviderArray = null ) : Promise < ComponentRef > {
35
- NativeScriptDomAdapter . makeCurrent ( ) ;
36
-
37
- let nativeScriptProviders : ProviderArray = [
38
- NativeScriptRootRenderer ,
39
- provide ( RootRenderer , { useClass : NativeScriptRootRenderer } ) ,
40
- NativeScriptRenderer ,
41
- provide ( Renderer , { useClass : NativeScriptRenderer } ) ,
42
- provide ( XHR , { useClass : FileSystemXHR } ) ,
43
- provide ( ExceptionHandler , { useFactory : ( ) => new ExceptionHandler ( DOM , true ) , deps : [ ] } ) ,
44
-
45
- provide ( PLATFORM_PIPES , { useValue : COMMON_PIPES , multi : true } ) ,
46
- provide ( PLATFORM_DIRECTIVES , { useValue : COMMON_DIRECTIVES , multi : true } ) ,
47
- provide ( PLATFORM_DIRECTIVES , { useValue : NS_DIRECTIVES , multi : true } ) ,
48
-
49
- APPLICATION_COMMON_PROVIDERS ,
50
- COMPILER_PROVIDERS ,
51
- PLATFORM_COMMON_PROVIDERS ,
52
- FORM_PROVIDERS ,
53
- ] ;
54
-
55
- var appProviders = [ ] ;
56
- if ( isPresent ( customProviders ) ) {
57
- appProviders . push ( customProviders ) ;
58
- }
59
-
60
- return platform ( nativeScriptProviders ) . application ( appProviders ) . bootstrap ( appComponentType ) ;
38
+ export function bootstrap ( appComponentType : any ,
39
+ customProviders : ProviderArray = null , appOptions : any = null ) : Promise < ComponentRef > {
40
+ NativeScriptDomAdapter . makeCurrent ( ) ;
41
+
42
+ let nativeScriptProviders : ProviderArray = [
43
+ NativeScriptRootRenderer ,
44
+ provide ( RootRenderer , { useClass : NativeScriptRootRenderer } ) ,
45
+ NativeScriptRenderer ,
46
+ provide ( Renderer , { useClass : NativeScriptRenderer } ) ,
47
+ provide ( XHR , { useClass : FileSystemXHR } ) ,
48
+ provide ( ExceptionHandler , { useFactory : ( ) => new ExceptionHandler ( DOM , true ) , deps : [ ] } ) ,
49
+
50
+ provide ( PLATFORM_PIPES , { useValue : COMMON_PIPES , multi : true } ) ,
51
+ provide ( PLATFORM_DIRECTIVES , { useValue : COMMON_DIRECTIVES , multi : true } ) ,
52
+ provide ( PLATFORM_DIRECTIVES , { useValue : NS_DIRECTIVES , multi : true } ) ,
53
+
54
+ APPLICATION_COMMON_PROVIDERS ,
55
+ COMPILER_PROVIDERS ,
56
+ PLATFORM_COMMON_PROVIDERS ,
57
+ FORM_PROVIDERS ,
58
+ ] ;
59
+
60
+ var appProviders = [ ] ;
61
+ if ( isPresent ( customProviders ) ) {
62
+ appProviders . push ( customProviders ) ;
63
+ }
64
+
65
+ return platform ( nativeScriptProviders ) . application ( appProviders ) . bootstrap ( appComponentType ) ;
66
+ }
67
+
68
+ export function nativeScriptBootstrap ( appComponentType : any , customProviders ?: ProviderArray , appOptions ?: any ) {
69
+ if ( appOptions && appOptions . cssFile ) {
70
+ application . cssFile = appOptions . cssFile ;
71
+ }
72
+ application . start ( {
73
+ create : ( ) : Page => {
74
+ let page = new Page ( ) ;
75
+
76
+ page . on ( 'loaded' , ( args ) => {
77
+ //profiling.stop('application-start');
78
+ console . log ( 'Page loaded' ) ;
79
+
80
+ //profiling.start('ng-bootstrap');
81
+ console . log ( 'BOOTSTRAPPING...' ) ;
82
+ bootstrap ( appComponentType ) . then ( ( appRef ) => {
83
+ //profiling.stop('ng-bootstrap');
84
+ console . log ( 'ANGULAR BOOTSTRAP DONE.' ) ;
85
+ } , ( err ) => {
86
+ console . log ( 'ERROR BOOTSTRAPPING ANGULAR' ) ;
87
+ let errorMessage = err . message + "\n\n" + err . stack ;
88
+ console . log ( errorMessage ) ;
89
+
90
+ let view = new TextView ( ) ;
91
+ view . text = errorMessage ;
92
+ topmost ( ) . currentPage . content = view ;
93
+ } ) ;
94
+ } ) ;
95
+
96
+ return page ;
97
+ }
98
+ } ) ;
61
99
}
0 commit comments