1+ export { BROWSER_PROVIDERS } from 'angular2/src/platform/browser_common' ;
2+
3+ import { Type , isPresent , CONST_EXPR } from 'angular2/src/facade/lang' ;
4+ import { Promise } from 'angular2/src/facade/promise' ;
5+ import {
6+ BROWSER_PROVIDERS ,
7+ BROWSER_APP_COMMON_PROVIDERS ,
8+ initBrowser
9+ } from 'angular2/src/platform/browser_common' ;
10+ import { COMPILER_PROVIDERS } from 'angular2/compiler' ;
11+ import { ComponentRef , platform , reflector } from 'angular2/core' ;
12+ import { ReflectionCapabilities } from 'angular2/src/core/reflection/reflection_capabilities' ;
13+
14+ /**
15+ * An array of providers that should be passed into `application()` when bootstrapping a component.
16+ */
17+ export const BROWSER_APP_PROVIDERS : Array < any /*Type | Provider | any[]*/ > =
18+ CONST_EXPR ( [ BROWSER_APP_COMMON_PROVIDERS , COMPILER_PROVIDERS ] ) ;
19+
20+ /**
21+ * Bootstrapping for Angular applications.
22+ *
23+ * You instantiate an Angular application by explicitly specifying a component to use
24+ * as the root component for your application via the `bootstrap()` method.
25+ *
26+ * ## Simple Example
27+ *
28+ * Assuming this `index.html`:
29+ *
30+ * ```html
31+ * <html>
32+ * <!-- load Angular script tags here. -->
33+ * <body>
34+ * <my-app>loading...</my-app>
35+ * </body>
36+ * </html>
37+ * ```
38+ *
39+ * An application is bootstrapped inside an existing browser DOM, typically `index.html`.
40+ * Unlike Angular 1, Angular 2 does not compile/process providers in `index.html`. This is
41+ * mainly for security reasons, as well as architectural changes in Angular 2. This means
42+ * that `index.html` can safely be processed using server-side technologies such as
43+ * providers. Bindings can thus use double-curly `{{ syntax }}` without collision from
44+ * Angular 2 component double-curly `{{ syntax }}`.
45+ *
46+ * We can use this script code:
47+ *
48+ * ```
49+ * @Component ({
50+ * selector: 'my-app',
51+ * template: 'Hello {{ name }}!'
52+ * })
53+ * class MyApp {
54+ * name:string;
55+ *
56+ * constructor() {
57+ * this.name = 'World';
58+ * }
59+ * }
60+ *
61+ * main() {
62+ * return bootstrap(MyApp);
63+ * }
64+ * ```
65+ *
66+ * When the app developer invokes `bootstrap()` with the root component `MyApp` as its
67+ * argument, Angular performs the following tasks:
68+ *
69+ * 1. It uses the component's `selector` property to locate the DOM element which needs
70+ * to be upgraded into the angular component.
71+ * 2. It creates a new child injector (from the platform injector). Optionally, you can
72+ * also override the injector configuration for an app by invoking `bootstrap` with the
73+ * `componentInjectableBindings` argument.
74+ * 3. It creates a new `Zone` and connects it to the angular application's change detection
75+ * domain instance.
76+ * 4. It creates an emulated or shadow DOM on the selected component's host element and loads the
77+ * template into it.
78+ * 5. It instantiates the specified component.
79+ * 6. Finally, Angular performs change detection to apply the initial data providers for the
80+ * application.
81+ *
82+ *
83+ * ## Bootstrapping Multiple Applications
84+ *
85+ * When working within a browser window, there are many singleton resources: cookies, title,
86+ * location, and others. Angular services that represent these resources must likewise be
87+ * shared across all Angular applications that occupy the same browser window. For this
88+ * reason, Angular creates exactly one global platform object which stores all shared
89+ * services, and each angular application injector has the platform injector as its parent.
90+ *
91+ * Each application has its own private injector as well. When there are multiple
92+ * applications on a page, Angular treats each application injector's services as private
93+ * to that application.
94+ *
95+ * ## API
96+ *
97+ * - `appComponentType`: The root component which should act as the application. This is
98+ * a reference to a `Type` which is annotated with `@Component(...)`.
99+ * - `customProviders`: An additional set of providers that can be added to the
100+ * app injector to override default injection behavior.
101+ *
102+ * Returns a `Promise` of {@link ComponentRef}.
103+ */
104+ export function bootstrap (
105+ appComponentType : Type ,
106+ customProviders ?: Array < any /*Type | Provider | any[]*/ > ) : Promise < ComponentRef > {
107+ reflector . reflectionCapabilities = new ReflectionCapabilities ( ) ;
108+ initBrowser ( ) ;
109+
110+ let appProviders =
111+ isPresent ( customProviders ) ? [ BROWSER_APP_PROVIDERS , customProviders ] : BROWSER_APP_PROVIDERS ;
112+ return platform ( BROWSER_PROVIDERS ) . application ( appProviders ) . bootstrap ( appComponentType ) ;
113+ }
0 commit comments