UNPKG

9.22 kBTypeScriptView Raw
1/**
2 * @license
3 * Copyright Google Inc. All Rights Reserved.
4 *
5 * Use of this source code is governed by an MIT-style license that can be
6 * found in the LICENSE file at https://angular.io/license
7 */
8import { ErrorHandler } from '../src/error_handler';
9import { ApplicationInitStatus } from './application_init';
10import { Console } from './console';
11import { Injector, Provider } from './di';
12import { CompilerOptions } from './linker/compiler';
13import { ComponentFactory, ComponentRef } from './linker/component_factory';
14import { ComponentFactoryResolver } from './linker/component_factory_resolver';
15import { NgModuleFactory, NgModuleRef } from './linker/ng_module_factory';
16import { ViewRef } from './linker/view_ref';
17import { Testability, TestabilityRegistry } from './testability/testability';
18import { Type } from './type';
19import { NgZone } from './zone/ng_zone';
20/**
21 * Disable Angular's development mode, which turns off assertions and other
22 * checks within the framework.
23 *
24 * One important assertion this disables verifies that a change detection pass
25 * does not result in additional changes to any bindings (also known as
26 * unidirectional data flow).
27 *
28 * @stable
29 */
30export declare function enableProdMode(): void;
31/**
32 * Returns whether Angular is in development mode. After called once,
33 * the value is locked and won't change any more.
34 *
35 * By default, this is true, unless a user calls `enableProdMode` before calling this.
36 *
37 * @experimental APIs related to application bootstrap are currently under review.
38 */
39export declare function isDevMode(): boolean;
40/**
41 * A token for third-party components that can register themselves with NgProbe.
42 *
43 * @experimental
44 */
45export declare class NgProbeToken {
46 name: string;
47 token: any;
48 constructor(name: string, token: any);
49}
50/**
51 * Creates a platform.
52 * Platforms have to be eagerly created via this function.
53 *
54 * @experimental APIs related to application bootstrap are currently under review.
55 */
56export declare function createPlatform(injector: Injector): PlatformRef;
57/**
58 * Creates a factory for a platform
59 *
60 * @experimental APIs related to application bootstrap are currently under review.
61 */
62export declare function createPlatformFactory(parentPlatformFactory: (extraProviders?: Provider[]) => PlatformRef, name: string, providers?: Provider[]): (extraProviders?: Provider[]) => PlatformRef;
63/**
64 * Checks that there currently is a platform
65 * which contains the given token as a provider.
66 *
67 * @experimental APIs related to application bootstrap are currently under review.
68 */
69export declare function assertPlatform(requiredToken: any): PlatformRef;
70/**
71 * Destroy the existing platform.
72 *
73 * @experimental APIs related to application bootstrap are currently under review.
74 */
75export declare function destroyPlatform(): void;
76/**
77 * Returns the current platform.
78 *
79 * @experimental APIs related to application bootstrap are currently under review.
80 */
81export declare function getPlatform(): PlatformRef;
82/**
83 * The Angular platform is the entry point for Angular on a web page. Each page
84 * has exactly one platform, and services (such as reflection) which are common
85 * to every Angular application running on the page are bound in its scope.
86 *
87 * A page's platform is initialized implicitly when {@link bootstrap}() is called, or
88 * explicitly by calling {@link createPlatform}().
89 *
90 * @stable
91 */
92export declare abstract class PlatformRef {
93 /**
94 * Creates an instance of an `@NgModule` for the given platform
95 * for offline compilation.
96 *
97 * ## Simple Example
98 *
99 * ```typescript
100 * my_module.ts:
101 *
102 * @NgModule({
103 * imports: [BrowserModule]
104 * })
105 * class MyModule {}
106 *
107 * main.ts:
108 * import {MyModuleNgFactory} from './my_module.ngfactory';
109 * import {platformBrowser} from '@angular/platform-browser';
110 *
111 * let moduleRef = platformBrowser().bootstrapModuleFactory(MyModuleNgFactory);
112 * ```
113 *
114 * @experimental APIs related to application bootstrap are currently under review.
115 */
116 abstract bootstrapModuleFactory<M>(moduleFactory: NgModuleFactory<M>): Promise<NgModuleRef<M>>;
117 /**
118 * Creates an instance of an `@NgModule` for a given platform using the given runtime compiler.
119 *
120 * ## Simple Example
121 *
122 * ```typescript
123 * @NgModule({
124 * imports: [BrowserModule]
125 * })
126 * class MyModule {}
127 *
128 * let moduleRef = platformBrowser().bootstrapModule(MyModule);
129 * ```
130 * @stable
131 */
132 abstract bootstrapModule<M>(moduleType: Type<M>, compilerOptions?: CompilerOptions | CompilerOptions[]): Promise<NgModuleRef<M>>;
133 /**
134 * Register a listener to be called when the platform is disposed.
135 */
136 abstract onDestroy(callback: () => void): void;
137 /**
138 * Retrieve the platform {@link Injector}, which is the parent injector for
139 * every Angular application on the page and provides singleton providers.
140 */
141 injector: Injector;
142 /**
143 * Destroy the Angular platform and all Angular applications on the page.
144 */
145 abstract destroy(): void;
146 destroyed: boolean;
147}
148export declare class PlatformRef_ extends PlatformRef {
149 private _injector;
150 private _modules;
151 private _destroyListeners;
152 private _destroyed;
153 constructor(_injector: Injector);
154 onDestroy(callback: () => void): void;
155 injector: Injector;
156 destroyed: boolean;
157 destroy(): void;
158 bootstrapModuleFactory<M>(moduleFactory: NgModuleFactory<M>): Promise<NgModuleRef<M>>;
159 private _bootstrapModuleFactoryWithZone<M>(moduleFactory, ngZone);
160 bootstrapModule<M>(moduleType: Type<M>, compilerOptions?: CompilerOptions | CompilerOptions[]): Promise<NgModuleRef<M>>;
161 private _bootstrapModuleWithZone<M>(moduleType, compilerOptions, ngZone, componentFactoryCallback?);
162 private _moduleDoBootstrap(moduleRef);
163}
164/**
165 * A reference to an Angular application running on a page.
166 *
167 * For more about Angular applications, see the documentation for {@link bootstrap}.
168 *
169 * @stable
170 */
171export declare abstract class ApplicationRef {
172 /**
173 * Bootstrap a new component at the root level of the application.
174 *
175 * ### Bootstrap process
176 *
177 * When bootstrapping a new root component into an application, Angular mounts the
178 * specified application component onto DOM elements identified by the [componentType]'s
179 * selector and kicks off automatic change detection to finish initializing the component.
180 *
181 * ### Example
182 * {@example core/ts/platform/platform.ts region='longform'}
183 */
184 abstract bootstrap<C>(componentFactory: ComponentFactory<C> | Type<C>): ComponentRef<C>;
185 /**
186 * Invoke this method to explicitly process change detection and its side-effects.
187 *
188 * In development mode, `tick()` also performs a second change detection cycle to ensure that no
189 * further changes are detected. If additional changes are picked up during this second cycle,
190 * bindings in the app have side-effects that cannot be resolved in a single change detection
191 * pass.
192 * In this case, Angular throws an error, since an Angular application can only have one change
193 * detection pass during which all change detection must complete.
194 */
195 abstract tick(): void;
196 /**
197 * Get a list of component types registered to this application.
198 * This list is populated even before the component is created.
199 */
200 componentTypes: Type<any>[];
201 /**
202 * Get a list of components registered to this application.
203 */
204 components: ComponentRef<any>[];
205 /**
206 * Attaches a view so that it will be dirty checked.
207 * The view will be automatically detached when it is destroyed.
208 * This will throw if the view is already attached to a ViewContainer.
209 */
210 abstract attachView(view: ViewRef): void;
211 /**
212 * Detaches a view from dirty checking again.
213 */
214 abstract detachView(view: ViewRef): void;
215 /**
216 * Returns the number of attached views.
217 */
218 viewCount: number;
219}
220export declare class ApplicationRef_ extends ApplicationRef {
221 private _zone;
222 private _console;
223 private _injector;
224 private _exceptionHandler;
225 private _componentFactoryResolver;
226 private _initStatus;
227 private _testabilityRegistry;
228 private _testability;
229 private _bootstrapListeners;
230 private _rootComponents;
231 private _rootComponentTypes;
232 private _views;
233 private _runningTick;
234 private _enforceNoNewChanges;
235 constructor(_zone: NgZone, _console: Console, _injector: Injector, _exceptionHandler: ErrorHandler, _componentFactoryResolver: ComponentFactoryResolver, _initStatus: ApplicationInitStatus, _testabilityRegistry: TestabilityRegistry, _testability: Testability);
236 attachView(viewRef: ViewRef): void;
237 detachView(viewRef: ViewRef): void;
238 bootstrap<C>(componentOrFactory: ComponentFactory<C> | Type<C>): ComponentRef<C>;
239 private _loadComponent(componentRef);
240 private _unloadComponent(componentRef);
241 tick(): void;
242 ngOnDestroy(): void;
243 viewCount: number;
244 componentTypes: Type<any>[];
245 components: ComponentRef<any>[];
246}