diff --git a/packages/core/src/metadata.ts b/packages/core/src/metadata.ts index e606c12fa4..d377b0afae 100644 --- a/packages/core/src/metadata.ts +++ b/packages/core/src/metadata.ts @@ -13,11 +13,11 @@ import {Attribute, ContentChild, ContentChildren, Query, ViewChild, ViewChildren} from './metadata/di'; import {Component, Directive, HostBinding, HostListener, Input, Output, Pipe} from './metadata/directives'; -import {ModuleWithProviders, NgModule, SchemaMetadata} from './metadata/ng_module'; +import {DoBootstrap, ModuleWithProviders, NgModule, SchemaMetadata} from './metadata/ng_module'; import {ViewEncapsulation} from './metadata/view'; export {ANALYZE_FOR_ENTRY_COMPONENTS, Attribute, ContentChild, ContentChildDecorator, ContentChildren, ContentChildrenDecorator, Query, ViewChild, ViewChildDecorator, ViewChildren, ViewChildrenDecorator} from './metadata/di'; export {Component, ComponentDecorator, Directive, DirectiveDecorator, HostBinding, HostListener, Input, Output, Pipe} from './metadata/directives'; export {AfterContentChecked, AfterContentInit, AfterViewChecked, AfterViewInit, DoCheck, OnChanges, OnDestroy, OnInit} from './metadata/lifecycle_hooks'; -export {CUSTOM_ELEMENTS_SCHEMA, ModuleWithProviders, NO_ERRORS_SCHEMA, NgModule, SchemaMetadata} from './metadata/ng_module'; +export {CUSTOM_ELEMENTS_SCHEMA, DoBootstrap, ModuleWithProviders, NO_ERRORS_SCHEMA, NgModule, SchemaMetadata} from './metadata/ng_module'; export {ViewEncapsulation} from './metadata/view'; diff --git a/packages/core/src/metadata/ng_module.ts b/packages/core/src/metadata/ng_module.ts index 124bd314e3..6bab5807d6 100644 --- a/packages/core/src/metadata/ng_module.ts +++ b/packages/core/src/metadata/ng_module.ts @@ -6,6 +6,7 @@ * found in the LICENSE file at https://angular.io/license */ +import {ApplicationRef} from '../application_ref'; import {InjectorDef, InjectorType, defineInjector} from '../di/defs'; import {convertInjectableProviderToFactory} from '../di/injectable'; import {Provider} from '../di/provider'; @@ -352,3 +353,24 @@ export const NgModule: NgModuleDecorator = makeDecorator( * this module's members available to others. */ (type: Type, meta: NgModule) => (R3_COMPILE_NGMODULE || preR3NgModuleCompile)(type, meta)); + +/** + * @description + * Hook for manual bootstrapping of the application instead of using bootstrap array in @NgModule + * annotation. + * + * Reference to the current application is provided as a parameter. + * + * See ["Bootstrapping"](guide/bootstrapping) and ["Entry components"](guide/entry-components). + * + * @usageNotes + * ```typescript + * class AppModule implements DoBootstrap { + * ngDoBootstrap(appRef: ApplicationRef) { + * appRef.bootstrap(AppComponent); // Or some other component + * } + * } + * ``` + * + */ +export interface DoBootstrap { ngDoBootstrap(appRef: ApplicationRef): void; } diff --git a/packages/elements/test/create-custom-element_spec.ts b/packages/elements/test/create-custom-element_spec.ts index 94be8b4137..299ecaf015 100644 --- a/packages/elements/test/create-custom-element_spec.ts +++ b/packages/elements/test/create-custom-element_spec.ts @@ -6,7 +6,7 @@ * found in the LICENSE file at https://angular.io/license */ -import {Component, EventEmitter, Injector, Input, NgModule, Output, destroyPlatform} from '@angular/core'; +import {Component, DoBootstrap, EventEmitter, Injector, Input, NgModule, Output, destroyPlatform} from '@angular/core'; import {BrowserModule} from '@angular/platform-browser'; import {platformBrowserDynamic} from '@angular/platform-browser-dynamic'; import {Subject} from 'rxjs'; @@ -109,13 +109,12 @@ class TestComponent { @Output() bazBaz = new EventEmitter(); @Output('quxqux') quxQux = new EventEmitter(); } - @NgModule({ imports: [BrowserModule], declarations: [TestComponent], entryComponents: [TestComponent], }) -class TestModule { +class TestModule implements DoBootstrap { ngDoBootstrap() {} } diff --git a/tools/public_api_guard/core/core.d.ts b/tools/public_api_guard/core/core.d.ts index e085f7e171..669cef1730 100644 --- a/tools/public_api_guard/core/core.d.ts +++ b/tools/public_api_guard/core/core.d.ts @@ -267,6 +267,10 @@ export interface DirectiveDecorator { new (obj: Directive): Directive; } +export interface DoBootstrap { + ngDoBootstrap(appRef: ApplicationRef): void; +} + export interface DoCheck { ngDoCheck(): void; }