refactor(core): remove deprecated 'bootstrap' (#10831)
This commit is contained in:
@ -77,8 +77,6 @@ export class SwitchView {
|
||||
* this.value = this.value === 'init' ? 0 : this.value + 1;
|
||||
* }
|
||||
* }
|
||||
*
|
||||
* bootstrap(App).catch(err => console.error(err));
|
||||
* ```
|
||||
*
|
||||
* @experimental
|
||||
|
@ -28,32 +28,16 @@ import {PlatformLocation, UrlChangeListener} from './platform_location';
|
||||
* ### Example
|
||||
*
|
||||
* ```
|
||||
* import {Component, provide} from '@angular/core';
|
||||
* import {Component, NgModule} from '@angular/core';
|
||||
* import {
|
||||
* Location,
|
||||
* LocationStrategy,
|
||||
* HashLocationStrategy
|
||||
* } from '@angular/common';
|
||||
* import {
|
||||
* ROUTER_DIRECTIVES,
|
||||
* ROUTER_PROVIDERS,
|
||||
* RouteConfig
|
||||
* } from '@angular/router';
|
||||
*
|
||||
* @Component({directives: [ROUTER_DIRECTIVES]})
|
||||
* @RouteConfig([
|
||||
* {...},
|
||||
* ])
|
||||
* class AppCmp {
|
||||
* constructor(location: Location) {
|
||||
* location.go('/foo');
|
||||
* }
|
||||
* }
|
||||
*
|
||||
* bootstrap(AppCmp, [
|
||||
* ROUTER_PROVIDERS,
|
||||
* {provide: LocationStrategy, useClass: HashLocationStrategy}
|
||||
* ]);
|
||||
* @NgModule({
|
||||
* providers: [{provide: LocationStrategy, useClass: HashLocationStrategy}]
|
||||
* })
|
||||
* class AppModule {}
|
||||
* ```
|
||||
*
|
||||
* @stable
|
||||
|
@ -32,23 +32,13 @@ import {LocationStrategy} from './location_strategy';
|
||||
* ```
|
||||
* import {Component} from '@angular/core';
|
||||
* import {Location} from '@angular/common';
|
||||
* import {
|
||||
* ROUTER_DIRECTIVES,
|
||||
* ROUTER_PROVIDERS,
|
||||
* RouteConfig
|
||||
* } from '@angular/router';
|
||||
*
|
||||
* @Component({directives: [ROUTER_DIRECTIVES]})
|
||||
* @RouteConfig([
|
||||
* {...},
|
||||
* ])
|
||||
* @Component({selector: 'app-component'})
|
||||
* class AppCmp {
|
||||
* constructor(location: Location) {
|
||||
* location.go('/foo');
|
||||
* }
|
||||
* }
|
||||
*
|
||||
* bootstrap(AppCmp, [ROUTER_PROVIDERS]);
|
||||
* ```
|
||||
*
|
||||
* @stable
|
||||
|
@ -49,24 +49,15 @@ export abstract class LocationStrategy {
|
||||
*
|
||||
* ### Example
|
||||
*
|
||||
* ```
|
||||
* import {Component} from '@angular/core';
|
||||
* import {ROUTER_DIRECTIVES, ROUTER_PROVIDERS, RouteConfig} from '@angular/router';
|
||||
* import {Component, NgModule} from '@angular/core';
|
||||
* import {APP_BASE_HREF} from '@angular/common';
|
||||
*
|
||||
* @Component({directives: [ROUTER_DIRECTIVES]})
|
||||
* @RouteConfig([
|
||||
* {...},
|
||||
* ])
|
||||
* class AppCmp {
|
||||
* // ...
|
||||
* }
|
||||
*
|
||||
* bootstrap(AppCmp, [
|
||||
* ROUTER_PROVIDERS,
|
||||
* {provide: APP_BASE_HREF, useValue: '/my/app'}
|
||||
* ]);
|
||||
* @NgModule({
|
||||
* providers: [{provide: APP_BASE_HREF, useValue: '/my/app'}]
|
||||
* })
|
||||
* class AppModule {}
|
||||
* ```
|
||||
*
|
||||
* @stable
|
||||
*/
|
||||
export const APP_BASE_HREF: OpaqueToken = new OpaqueToken('appBaseHref');
|
||||
|
@ -110,7 +110,7 @@ export function analyzeAppProvidersForDeprecatedConfiguration(appProviders: any[
|
||||
useDebug = compilerConfig.genDebugInfo;
|
||||
defaultEncapsulation = compilerConfig.defaultEncapsulation;
|
||||
deprecationMessages.push(
|
||||
`Passing CompilerConfig as a regular provider is deprecated. Use the "compilerOptions" parameter of "bootstrap()" or use a custom "CompilerFactory" platform provider instead.`);
|
||||
`Passing CompilerConfig as a regular provider is deprecated. Use "compilerOptions" use a custom "CompilerFactory" platform provider instead.`);
|
||||
}
|
||||
const xhr = tempInj.get(XHR, null);
|
||||
if (xhr) {
|
||||
|
@ -45,8 +45,6 @@ export abstract class ChangeDetectorRef {
|
||||
* })
|
||||
* class App {
|
||||
* }
|
||||
*
|
||||
* bootstrap(App);
|
||||
* ```
|
||||
*/
|
||||
abstract markForCheck(): void;
|
||||
@ -104,8 +102,6 @@ export abstract class ChangeDetectorRef {
|
||||
* })
|
||||
* class App {
|
||||
* }
|
||||
*
|
||||
* bootstrap(App);
|
||||
* ```
|
||||
*/
|
||||
abstract detach(): void;
|
||||
@ -195,8 +191,6 @@ export abstract class ChangeDetectorRef {
|
||||
* class App {
|
||||
* live = true;
|
||||
* }
|
||||
*
|
||||
* bootstrap(App);
|
||||
* ```
|
||||
*/
|
||||
abstract reattach(): void;
|
||||
|
@ -237,8 +237,6 @@ export class SkipSelfMetadata {
|
||||
* })
|
||||
* class App {
|
||||
* }
|
||||
*
|
||||
* bootstrap(App);
|
||||
*```
|
||||
* @stable
|
||||
*/
|
||||
|
@ -981,8 +981,6 @@ export var Pipe: PipeMetadataFactory = <PipeMetadataFactory>makeDecorator(PipeMe
|
||||
* directives: [BankAccount]
|
||||
* })
|
||||
* class App {}
|
||||
*
|
||||
* bootstrap(App);
|
||||
* ```
|
||||
* @stable
|
||||
* @Annotation
|
||||
@ -1028,7 +1026,6 @@ export var Input: InputMetadataFactory = makePropDecorator(InputMetadata);
|
||||
* everySecond() { console.log('second'); }
|
||||
* everyFiveSeconds() { console.log('five seconds'); }
|
||||
* }
|
||||
* bootstrap(App);
|
||||
* ```
|
||||
* @stable
|
||||
* @Annotation
|
||||
@ -1067,8 +1064,6 @@ export var Output: OutputMetadataFactory = makePropDecorator(OutputMetadata);
|
||||
* class App {
|
||||
* prop;
|
||||
* }
|
||||
*
|
||||
* bootstrap(App);
|
||||
* ```
|
||||
* @stable
|
||||
* @Annotation
|
||||
@ -1106,8 +1101,6 @@ export var HostBinding: HostBindingMetadataFactory = makePropDecorator(HostBindi
|
||||
* directives: [CountClicks]
|
||||
* })
|
||||
* class App {}
|
||||
*
|
||||
* bootstrap(App);
|
||||
* ```
|
||||
* @stable
|
||||
* @Annotation
|
||||
|
@ -485,8 +485,6 @@ export class DirectiveMetadata extends InjectableMetadata implements DirectiveMe
|
||||
* directives: [BankAccount]
|
||||
* })
|
||||
* class App {}
|
||||
*
|
||||
* bootstrap(App);
|
||||
* ```
|
||||
*
|
||||
*/
|
||||
@ -534,7 +532,6 @@ export class DirectiveMetadata extends InjectableMetadata implements DirectiveMe
|
||||
* everySecond() { console.log('second'); }
|
||||
* everyFiveSeconds() { console.log('five seconds'); }
|
||||
* }
|
||||
* bootstrap(App);
|
||||
* ```
|
||||
*
|
||||
*/
|
||||
@ -585,8 +582,6 @@ export class DirectiveMetadata extends InjectableMetadata implements DirectiveMe
|
||||
* directives: [CountClicks]
|
||||
* })
|
||||
* class App {}
|
||||
*
|
||||
* bootstrap(App);
|
||||
* ```
|
||||
*
|
||||
* ## Host Property Bindings
|
||||
@ -623,8 +618,6 @@ export class DirectiveMetadata extends InjectableMetadata implements DirectiveMe
|
||||
* class App {
|
||||
* prop;
|
||||
* }
|
||||
*
|
||||
* bootstrap(App);
|
||||
* ```
|
||||
*
|
||||
* ## Attributes
|
||||
@ -1103,8 +1096,6 @@ export class PipeMetadata extends InjectableMetadata implements PipeMetadataType
|
||||
* directives: [BankAccount]
|
||||
* })
|
||||
* class App {}
|
||||
*
|
||||
* bootstrap(App);
|
||||
* ```
|
||||
* @stable
|
||||
*/
|
||||
@ -1154,7 +1145,6 @@ export class InputMetadata {
|
||||
* everySecond() { console.log('second'); }
|
||||
* everyFiveSeconds() { console.log('five seconds'); }
|
||||
* }
|
||||
* bootstrap(App);
|
||||
* ```
|
||||
* @stable
|
||||
*/
|
||||
@ -1193,8 +1183,6 @@ export class OutputMetadata {
|
||||
* class App {
|
||||
* prop;
|
||||
* }
|
||||
*
|
||||
* bootstrap(App);
|
||||
* ```
|
||||
* @stable
|
||||
*/
|
||||
@ -1232,8 +1220,6 @@ export class HostBindingMetadata {
|
||||
* directives: [CountClicks]
|
||||
* })
|
||||
* class App {}
|
||||
*
|
||||
* bootstrap(App);
|
||||
* ```
|
||||
* @stable
|
||||
*/
|
||||
|
@ -81,8 +81,6 @@ export var LIFECYCLE_HOOKS_VALUES = [
|
||||
* export class App {
|
||||
* value = 0;
|
||||
* }
|
||||
*
|
||||
* bootstrap(App).catch(err => console.error(err));
|
||||
* ```
|
||||
* @stable
|
||||
*/
|
||||
@ -125,9 +123,7 @@ export abstract class OnChanges { abstract ngOnChanges(changes: SimpleChanges):
|
||||
* export class App {
|
||||
* hasChild = true;
|
||||
* }
|
||||
*
|
||||
* bootstrap(App).catch(err => console.error(err));
|
||||
* ```
|
||||
* ```
|
||||
* @stable
|
||||
*/
|
||||
export abstract class OnInit { abstract ngOnInit(): void; }
|
||||
@ -236,8 +232,6 @@ export abstract class DoCheck { abstract ngDoCheck(): void; }
|
||||
* export class App {
|
||||
* hasChild = true;
|
||||
* }
|
||||
*
|
||||
* bootstrap(App).catch(err => console.error(err));
|
||||
* ```
|
||||
*
|
||||
*
|
||||
@ -340,8 +334,6 @@ export abstract class OnDestroy { abstract ngOnDestroy(): void; }
|
||||
* })
|
||||
* export class App {
|
||||
* }
|
||||
*
|
||||
* bootstrap(App).catch(err => console.error(err));
|
||||
* ```
|
||||
* @stable
|
||||
*/
|
||||
@ -389,8 +381,6 @@ export abstract class AfterContentInit { abstract ngAfterContentInit(): void; }
|
||||
* export class App {
|
||||
* hasContent = true;
|
||||
* }
|
||||
*
|
||||
* bootstrap(App).catch(err => console.error(err));
|
||||
* ```
|
||||
* @stable
|
||||
*/
|
||||
@ -437,8 +427,6 @@ export abstract class AfterContentChecked { abstract ngAfterContentChecked(): vo
|
||||
* })
|
||||
* export class App {
|
||||
* }
|
||||
*
|
||||
* bootstrap(App).catch(err => console.error(err));
|
||||
* ```
|
||||
* @stable
|
||||
*/
|
||||
@ -488,8 +476,6 @@ export abstract class AfterViewInit { abstract ngAfterViewInit(): void; }
|
||||
* })
|
||||
* export class App {
|
||||
* }
|
||||
*
|
||||
* bootstrap(App).catch(err => console.error(err));
|
||||
* ```
|
||||
* @stable
|
||||
*/
|
||||
|
@ -7,7 +7,9 @@
|
||||
*/
|
||||
|
||||
import {UrlResolver} from '@angular/compiler';
|
||||
import {bootstrap} from '@angular/platform-browser-dynamic';
|
||||
import {NgModule} from '@angular/core';
|
||||
import {BrowserModule} from '@angular/platform-browser';
|
||||
import {platformBrowserDynamic} from '@angular/platform-browser-dynamic';
|
||||
|
||||
var MyApp: any;
|
||||
|
||||
@ -22,5 +24,15 @@ class MyUrlResolver extends UrlResolver {
|
||||
}
|
||||
}
|
||||
|
||||
bootstrap(MyApp, [{provide: UrlResolver, useClass: MyUrlResolver}]);
|
||||
@NgModule({
|
||||
imports: [BrowserModule],
|
||||
providers: [{provide: UrlResolver, useClass: MyUrlResolver}],
|
||||
bootstrap: [MyApp]
|
||||
})
|
||||
class AppModule {
|
||||
}
|
||||
|
||||
export function main() {
|
||||
platformBrowserDynamic().bootstrapModule(AppModule);
|
||||
}
|
||||
// #enddocregion
|
||||
|
@ -6,8 +6,9 @@
|
||||
* found in the LICENSE file at https://angular.io/license
|
||||
*/
|
||||
|
||||
import {Component} from '@angular/core';
|
||||
import {bootstrap} from '@angular/platform-browser-dynamic';
|
||||
import {Component, NgModule} from '@angular/core';
|
||||
import {BrowserModule} from '@angular/platform-browser';
|
||||
import {platformBrowserDynamic} from '@angular/platform-browser-dynamic';
|
||||
import {Observable, Subscriber} from 'rxjs/Rx';
|
||||
|
||||
// #docregion AsyncPipePromise
|
||||
@ -62,6 +63,10 @@ class Task {
|
||||
export class AppCmp {
|
||||
}
|
||||
|
||||
export function main() {
|
||||
bootstrap(AppCmp);
|
||||
@NgModule({imports: [BrowserModule], bootstrap: [AppCmp]})
|
||||
class AppModule {
|
||||
}
|
||||
|
||||
export function main() {
|
||||
platformBrowserDynamic().bootstrapModule(AppModule);
|
||||
}
|
||||
|
@ -6,8 +6,9 @@
|
||||
* found in the LICENSE file at https://angular.io/license
|
||||
*/
|
||||
|
||||
import {Component} from '@angular/core';
|
||||
import {bootstrap} from '@angular/platform-browser-dynamic';
|
||||
import {Component, NgModule} from '@angular/core';
|
||||
import {BrowserModule} from '@angular/platform-browser';
|
||||
import {platformBrowserDynamic} from '@angular/platform-browser-dynamic';
|
||||
|
||||
// #docregion DatePipe
|
||||
@Component({
|
||||
@ -34,6 +35,10 @@ export class DatePipeExample {
|
||||
export class AppCmp {
|
||||
}
|
||||
|
||||
export function main() {
|
||||
bootstrap(AppCmp);
|
||||
@NgModule({imports: [BrowserModule], bootstrap: [AppCmp]})
|
||||
class AppModule {
|
||||
}
|
||||
|
||||
export function main() {
|
||||
platformBrowserDynamic().bootstrapModule(AppModule);
|
||||
}
|
@ -6,8 +6,9 @@
|
||||
* found in the LICENSE file at https://angular.io/license
|
||||
*/
|
||||
|
||||
import {Component} from '@angular/core';
|
||||
import {bootstrap} from '@angular/platform-browser-dynamic';
|
||||
import {Component, NgModule} from '@angular/core';
|
||||
import {BrowserModule} from '@angular/platform-browser';
|
||||
import {platformBrowserDynamic} from '@angular/platform-browser-dynamic';
|
||||
|
||||
// #docregion JsonPipe
|
||||
@Component({
|
||||
@ -35,6 +36,10 @@ export class JsonPipeExample {
|
||||
export class AppCmp {
|
||||
}
|
||||
|
||||
export function main() {
|
||||
bootstrap(AppCmp);
|
||||
@NgModule({imports: [BrowserModule], bootstrap: [AppCmp], declarations: [AppCmp, JsonPipeExample]})
|
||||
class AppModule {
|
||||
}
|
||||
|
||||
export function main() {
|
||||
platformBrowserDynamic().bootstrapModule(AppModule);
|
||||
}
|
@ -6,8 +6,9 @@
|
||||
* found in the LICENSE file at https://angular.io/license
|
||||
*/
|
||||
|
||||
import {Component} from '@angular/core';
|
||||
import {bootstrap} from '@angular/platform-browser-dynamic';
|
||||
import {Component, NgModule} from '@angular/core';
|
||||
import {BrowserModule} from '@angular/platform-browser';
|
||||
import {platformBrowserDynamic} from '@angular/platform-browser-dynamic';
|
||||
|
||||
// #docregion LowerUpperPipe
|
||||
@Component({
|
||||
@ -35,6 +36,10 @@ export class LowerUpperPipeExample {
|
||||
export class AppCmp {
|
||||
}
|
||||
|
||||
export function main() {
|
||||
bootstrap(AppCmp);
|
||||
@NgModule({imports: [BrowserModule], bootstrap: [AppCmp]})
|
||||
class AppModule {
|
||||
}
|
||||
|
||||
export function main() {
|
||||
platformBrowserDynamic().bootstrapModule(AppModule);
|
||||
}
|
||||
|
@ -6,8 +6,9 @@
|
||||
* found in the LICENSE file at https://angular.io/license
|
||||
*/
|
||||
|
||||
import {Component} from '@angular/core';
|
||||
import {bootstrap} from '@angular/platform-browser-dynamic';
|
||||
import {Component, NgModule} from '@angular/core';
|
||||
import {BrowserModule} from '@angular/platform-browser';
|
||||
import {platformBrowserDynamic} from '@angular/platform-browser-dynamic';
|
||||
|
||||
// #docregion NumberPipe
|
||||
@Component({
|
||||
@ -69,6 +70,10 @@ export class CurrencyPipeExample {
|
||||
export class AppCmp {
|
||||
}
|
||||
|
||||
export function main() {
|
||||
bootstrap(AppCmp);
|
||||
@NgModule({imports: [BrowserModule], bootstrap: [AppCmp]})
|
||||
class AppModule {
|
||||
}
|
||||
|
||||
export function main() {
|
||||
platformBrowserDynamic().bootstrapModule(AppModule);
|
||||
}
|
||||
|
@ -6,8 +6,9 @@
|
||||
* found in the LICENSE file at https://angular.io/license
|
||||
*/
|
||||
|
||||
import {Component} from '@angular/core';
|
||||
import {bootstrap} from '@angular/platform-browser-dynamic';
|
||||
import {Component, NgModule} from '@angular/core';
|
||||
import {BrowserModule} from '@angular/platform-browser';
|
||||
import {platformBrowserDynamic} from '@angular/platform-browser-dynamic';
|
||||
|
||||
// #docregion SlicePipe_string
|
||||
@Component({
|
||||
@ -50,6 +51,10 @@ export class SlicePipeListExample {
|
||||
export class AppCmp {
|
||||
}
|
||||
|
||||
export function main() {
|
||||
bootstrap(AppCmp);
|
||||
@NgModule({imports: [BrowserModule], bootstrap: [AppCmp]})
|
||||
class AppModule {
|
||||
}
|
||||
|
||||
export function main() {
|
||||
platformBrowserDynamic().bootstrapModule(AppModule);
|
||||
}
|
@ -6,8 +6,9 @@
|
||||
* found in the LICENSE file at https://angular.io/license
|
||||
*/
|
||||
|
||||
import {Component} from '@angular/core';
|
||||
import {bootstrap} from '@angular/platform-browser-dynamic';
|
||||
import {Component, NgModule} from '@angular/core';
|
||||
import {BrowserModule} from '@angular/platform-browser';
|
||||
import {platformBrowserDynamic} from '@angular/platform-browser-dynamic';
|
||||
|
||||
// #docregion bootstrap
|
||||
@Component({selector: 'my-app', template: 'Hello {{ name }}!'})
|
||||
@ -15,7 +16,12 @@ class MyApp {
|
||||
name: string = 'World';
|
||||
}
|
||||
|
||||
function main() {
|
||||
return bootstrap(MyApp);
|
||||
@NgModule({imports: [BrowserModule], bootstrap: [MyApp]})
|
||||
class AppModule {
|
||||
}
|
||||
|
||||
export function main() {
|
||||
platformBrowserDynamic().bootstrapModule(AppModule);
|
||||
}
|
||||
|
||||
// #enddocregion
|
||||
|
@ -7,10 +7,14 @@
|
||||
*/
|
||||
|
||||
// #docregion enableProdMode
|
||||
import {enableProdMode} from '@angular/core';
|
||||
import {bootstrap} from '@angular/platform-browser-dynamic';
|
||||
import {NgModule, enableProdMode} from '@angular/core';
|
||||
import {BrowserModule} from '@angular/platform-browser';
|
||||
import {platformBrowserDynamic} from '@angular/platform-browser-dynamic';
|
||||
import {MyComponent} from './my_component';
|
||||
|
||||
enableProdMode();
|
||||
bootstrap(MyComponent);
|
||||
@NgModule({imports: [BrowserModule], bootstrap: [MyComponent]})
|
||||
class AppModule {
|
||||
}
|
||||
platformBrowserDynamic().bootstrapModule(AppModule);
|
||||
// #enddocregion
|
||||
|
@ -6,13 +6,18 @@
|
||||
* found in the LICENSE file at https://angular.io/license
|
||||
*/
|
||||
|
||||
import {Component} from '@angular/core';
|
||||
import {bootstrap} from '@angular/platform-browser-dynamic';
|
||||
|
||||
import {Component, NgModule} from '@angular/core';
|
||||
import {BrowserModule} from '@angular/platform-browser';
|
||||
import {platformBrowserDynamic} from '@angular/platform-browser-dynamic';
|
||||
|
||||
@Component({selector: 'my-component'})
|
||||
class MyAppComponent {
|
||||
}
|
||||
|
||||
// #docregion providers
|
||||
bootstrap(MyAppComponent);
|
||||
@NgModule({imports: [BrowserModule], bootstrap: [MyAppComponent]})
|
||||
class AppModule {
|
||||
}
|
||||
platformBrowserDynamic().bootstrapModule(AppModule);
|
||||
// #enddocregion
|
||||
|
@ -35,8 +35,10 @@ class _ArrayLogger {
|
||||
* }
|
||||
* }
|
||||
*
|
||||
* bootstrap(MyApp, [{provide: ExceptionHandler, useClass: MyExceptionHandler}])
|
||||
*
|
||||
* @NgModule({
|
||||
* providers: [{provide: ExceptionHandler, useClass: MyExceptionHandler}]
|
||||
* })
|
||||
* class MyModule {}
|
||||
* ```
|
||||
* @stable
|
||||
*/
|
||||
|
@ -79,9 +79,6 @@ export {QueryEncoder, URLSearchParams} from './src/url_search_params';
|
||||
* this.active = !this.active;
|
||||
* }
|
||||
* }
|
||||
*
|
||||
* bootstrap(App)
|
||||
* .catch(err => console.error(err));
|
||||
* ```
|
||||
*
|
||||
* The primary public API included in `HTTP_PROVIDERS` is the {@link Http} class.
|
||||
@ -112,8 +109,11 @@ export {QueryEncoder, URLSearchParams} from './src/url_search_params';
|
||||
* search: string = 'coreTeam=true';
|
||||
* }
|
||||
*
|
||||
* bootstrap(App, [HTTP_PROVIDERS, {provide: RequestOptions, useClass: MyOptions}])
|
||||
* .catch(err => console.error(err));
|
||||
* @NgModule({
|
||||
* imports: [HttpModule],
|
||||
* providers: [{provide: RequestOptions, useClass: MyOptions}]
|
||||
* })
|
||||
* class MyModule {}
|
||||
* ```
|
||||
*
|
||||
* Likewise, to use a mock backend for unit tests, the {@link XHRBackend}
|
||||
|
@ -28,117 +28,6 @@ export const CACHED_TEMPLATE_PROVIDER: Provider[] = [{provide: XHR, useClass: Ca
|
||||
export const platformBrowserDynamic = createPlatformFactory(
|
||||
platformCoreDynamic, 'browserDynamic', INTERNAL_BROWSER_DYNAMIC_PLATFORM_PROVIDERS);
|
||||
|
||||
/**
|
||||
* Bootstrapping for Angular applications.
|
||||
*
|
||||
* You instantiate an Angular application by explicitly specifying a component to use
|
||||
* as the root component for your application via the `bootstrap()` method.
|
||||
*
|
||||
* ## Simple Example
|
||||
*
|
||||
* Assuming this `index.html`:
|
||||
*
|
||||
* ```html
|
||||
* <html>
|
||||
* <!-- load Angular script tags here. -->
|
||||
* <body>
|
||||
* <my-app>loading...</my-app>
|
||||
* </body>
|
||||
* </html>
|
||||
* ```
|
||||
*
|
||||
* An application is bootstrapped inside an existing browser DOM, typically `index.html`.
|
||||
* Unlike Angular 1, Angular 2 does not compile/process providers in `index.html`. This is
|
||||
* mainly for security reasons, as well as architectural changes in Angular 2. This means
|
||||
* that `index.html` can safely be processed using server-side technologies such as
|
||||
* providers. Bindings can thus use double-curly `{{ syntax }}` without collision from
|
||||
* Angular 2 component double-curly `{{ syntax }}`.
|
||||
*
|
||||
* We can use this script code:
|
||||
*
|
||||
* {@example core/ts/bootstrap/bootstrap.ts region='bootstrap'}
|
||||
*
|
||||
* When the app developer invokes `bootstrap()` with the root component `MyApp` as its
|
||||
* argument, Angular performs the following tasks:
|
||||
*
|
||||
* 1. It uses the component's `selector` property to locate the DOM element which needs
|
||||
* to be upgraded into the angular component.
|
||||
* 2. It creates a new child injector (from the platform injector). Optionally, you can
|
||||
* also override the injector configuration for an app by invoking `bootstrap` with the
|
||||
* `componentInjectableBindings` argument.
|
||||
* 3. It creates a new `Zone` and connects it to the angular application's change detection
|
||||
* domain instance.
|
||||
* 4. It creates an emulated or shadow DOM on the selected component's host element and loads the
|
||||
* template into it.
|
||||
* 5. It instantiates the specified component.
|
||||
* 6. Finally, Angular performs change detection to apply the initial data providers for the
|
||||
* application.
|
||||
*
|
||||
*
|
||||
* ## Bootstrapping Multiple Applications
|
||||
*
|
||||
* When working within a browser window, there are many singleton resources: cookies, title,
|
||||
* location, and others. Angular services that represent these resources must likewise be
|
||||
* shared across all Angular applications that occupy the same browser window. For this
|
||||
* reason, Angular creates exactly one global platform object which stores all shared
|
||||
* services, and each angular application injector has the platform injector as its parent.
|
||||
*
|
||||
* Each application has its own private injector as well. When there are multiple
|
||||
* applications on a page, Angular treats each application injector's services as private
|
||||
* to that application.
|
||||
*
|
||||
* ## API (version 1)
|
||||
*
|
||||
* - `appComponentType`: The root component which should act as the application. This is
|
||||
* a reference to a `Type` which is annotated with `@Component(...)`.
|
||||
* - `customProviders`: An additional set of providers that can be added to the
|
||||
* app injector to override default injection behavior.
|
||||
*
|
||||
* ## API (version 2)
|
||||
* - `appComponentType`: The root component which should act as the application. This is
|
||||
* a reference to a `Type` which is annotated with `@Component(...)`.
|
||||
* - `providers`, `declarations`, `imports`, `entryComponents`: Defines the properties
|
||||
* of the dynamically created module that is used to bootstrap the module.
|
||||
* - to configure the compiler, use the `compilerOptions` parameter.
|
||||
*
|
||||
* Returns a `Promise` of {@link ComponentRef}.
|
||||
*
|
||||
* @deprecated This api cannot be used with the offline compiler. Use
|
||||
* `PlatformRef.boostrapModule()` instead.
|
||||
*/
|
||||
// Note: We are using typescript overloads here to have 2 function signatures!
|
||||
export function bootstrap<C>(
|
||||
appComponentType: Type<C>, customProviders?: Provider[]): Promise<ComponentRef<C>> {
|
||||
let compilerOptions: CompilerOptions;
|
||||
let declarations: any[] = [];
|
||||
let entryComponents: any[] = [];
|
||||
let deprecationMessages: string[] = [];
|
||||
const deprecatedConfiguration = analyzeAppProvidersForDeprecatedConfiguration(customProviders);
|
||||
declarations = deprecatedConfiguration.moduleDeclarations.concat(declarations);
|
||||
compilerOptions = deprecatedConfiguration.compilerOptions;
|
||||
deprecationMessages = deprecatedConfiguration.deprecationMessages;
|
||||
|
||||
@NgModule({
|
||||
providers: customProviders,
|
||||
declarations: declarations.concat([appComponentType]),
|
||||
imports: [BrowserModule],
|
||||
entryComponents: entryComponents,
|
||||
bootstrap: [appComponentType],
|
||||
schemas: [CUSTOM_ELEMENTS_SCHEMA]
|
||||
})
|
||||
class DynamicModule {
|
||||
}
|
||||
|
||||
return platformBrowserDynamic()
|
||||
.bootstrapModule(DynamicModule, compilerOptions)
|
||||
.then((moduleRef) => {
|
||||
const console = moduleRef.injector.get(Console);
|
||||
deprecationMessages.forEach((msg) => console.warn(msg));
|
||||
const appRef: ApplicationRef = moduleRef.injector.get(ApplicationRef);
|
||||
return appRef.components[0];
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Bootstraps the worker ui.
|
||||
*
|
||||
|
@ -7,17 +7,18 @@
|
||||
*/
|
||||
|
||||
import {XHR} from '@angular/compiler';
|
||||
import {APP_INITIALIZER, Component, Directive, ExceptionHandler, Inject, Input, NgModule, OnDestroy, PLATFORM_INITIALIZER, Pipe, createPlatformFactory} from '@angular/core';
|
||||
import {APP_INITIALIZER, CUSTOM_ELEMENTS_SCHEMA, Component, Directive, ExceptionHandler, Inject, Input, NgModule, OnDestroy, PLATFORM_INITIALIZER, Pipe, createPlatformFactory} from '@angular/core';
|
||||
import {ApplicationRef, destroyPlatform} from '@angular/core/src/application_ref';
|
||||
import {Console} from '@angular/core/src/console';
|
||||
import {ComponentRef} from '@angular/core/src/linker/component_factory';
|
||||
import {Testability, TestabilityRegistry} from '@angular/core/src/testability/testability';
|
||||
import {AsyncTestCompleter, Log, afterEach, beforeEach, beforeEachProviders, ddescribe, describe, iit, inject, it} from '@angular/core/testing/testing_internal';
|
||||
import {BrowserModule} from '@angular/platform-browser';
|
||||
import {bootstrap, platformBrowserDynamic} from '@angular/platform-browser-dynamic';
|
||||
import {platformBrowserDynamic} from '@angular/platform-browser-dynamic';
|
||||
import {getDOM} from '@angular/platform-browser/src/dom/dom_adapter';
|
||||
import {DOCUMENT} from '@angular/platform-browser/src/dom/dom_tokens';
|
||||
import {expect} from '@angular/platform-browser/testing/matchers';
|
||||
|
||||
import {stringify} from '../../src/facade/lang';
|
||||
|
||||
@Component({selector: 'hello-app', template: '{{greeting}} world!'})
|
||||
@ -110,6 +111,21 @@ class DummyConsole implements Console {
|
||||
warn(message: string) { this.warnings.push(message); }
|
||||
}
|
||||
|
||||
|
||||
class TestModule {}
|
||||
function bootstrap(cmpType: any, providers: any = []): Promise<any> {
|
||||
@NgModule({
|
||||
imports: [BrowserModule],
|
||||
declarations: [cmpType],
|
||||
bootstrap: [cmpType],
|
||||
providers: providers,
|
||||
schemas: [CUSTOM_ELEMENTS_SCHEMA]
|
||||
})
|
||||
class TestModule {
|
||||
}
|
||||
return platformBrowserDynamic().bootstrapModule(TestModule);
|
||||
}
|
||||
|
||||
export function main() {
|
||||
var fakeDoc: any /** TODO #9100 */, el: any /** TODO #9100 */, el2: any /** TODO #9100 */,
|
||||
testProviders: any /** TODO #9100 */, lightDom: any /** TODO #9100 */;
|
||||
@ -147,10 +163,9 @@ export function main() {
|
||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
var logger = new _ArrayLogger();
|
||||
var exceptionHandler = new ExceptionHandler(logger, false);
|
||||
|
||||
var refPromise =
|
||||
bootstrap(HelloRootCmp, [{provide: ExceptionHandler, useValue: exceptionHandler}]);
|
||||
refPromise.then(null, (reason) => {
|
||||
bootstrap(HelloRootCmp, [
|
||||
{provide: ExceptionHandler, useValue: exceptionHandler}
|
||||
]).then(null, (reason) => {
|
||||
expect(reason.message).toContain('The selector "hello-app" did not match any elements');
|
||||
async.done();
|
||||
return null;
|
||||
@ -236,7 +251,7 @@ export function main() {
|
||||
HelloRootCmp3, [testProviders, {provide: 'appBinding', useValue: 'BoundValue'}]);
|
||||
|
||||
refPromise.then((ref) => {
|
||||
expect(ref.instance.appBinding).toEqual('BoundValue');
|
||||
expect(ref.injector.get('appBinding')).toEqual('BoundValue');
|
||||
async.done();
|
||||
});
|
||||
}));
|
||||
@ -246,7 +261,8 @@ export function main() {
|
||||
var refPromise = bootstrap(HelloRootCmp4, testProviders);
|
||||
|
||||
refPromise.then((ref) => {
|
||||
expect(ref.instance.appRef).toBe(ref.injector.get(ApplicationRef));
|
||||
const appRef = ref.injector.get(ApplicationRef);
|
||||
expect(appRef).toBeDefined();
|
||||
async.done();
|
||||
});
|
||||
}));
|
||||
@ -294,22 +310,6 @@ export function main() {
|
||||
});
|
||||
}));
|
||||
|
||||
// Note: This will soon be deprecated as bootstrap creates a separate injector for the compiler,
|
||||
// i.e. such providers needs to go into that injecotr (when calling `browserCompiler`);
|
||||
it('should still allow to provide a custom xhr via the regular providers',
|
||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
let spyXhr: XHR = {get: (url: string) => Promise.resolve('{{greeting}} world!')};
|
||||
bootstrap(HelloUrlCmp, testProviders.concat([
|
||||
{provide: XHR, useValue: spyXhr}
|
||||
])).then((compRef) => {
|
||||
expect(el).toHaveText('hello world!');
|
||||
expect(compilerConsole.warnings).toEqual([
|
||||
'Passing XHR as regular provider is deprecated. Pass the provider via "compilerOptions" instead.'
|
||||
]);
|
||||
async.done();
|
||||
});
|
||||
}));
|
||||
|
||||
it('should allow to pass schemas', inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
bootstrap(HelloCmpUsingCustomElement, testProviders).then((compRef) => {
|
||||
expect(el).toHaveText('hello world!');
|
||||
|
@ -68,18 +68,16 @@ function setupTestingRouter(
|
||||
@NgModule({
|
||||
exports: [RouterModule],
|
||||
providers: [
|
||||
ROUTER_PROVIDERS,
|
||||
{provide: Location, useClass: SpyLocation},
|
||||
ROUTER_PROVIDERS, {provide: Location, useClass: SpyLocation},
|
||||
{provide: LocationStrategy, useClass: MockLocationStrategy},
|
||||
{provide: NgModuleFactoryLoader, useClass: SpyNgModuleFactoryLoader},
|
||||
{
|
||||
{provide: NgModuleFactoryLoader, useClass: SpyNgModuleFactoryLoader}, {
|
||||
provide: Router,
|
||||
useFactory: setupTestingRouter,
|
||||
deps: [
|
||||
ComponentResolver, UrlSerializer, RouterOutletMap, Location, NgModuleFactoryLoader,
|
||||
Compiler, Injector, ROUTES
|
||||
]
|
||||
},
|
||||
}
|
||||
]
|
||||
})
|
||||
export class RouterTestingModule {
|
||||
|
Reference in New Issue
Block a user