PlatformRef
Angular 平台是 Angular 在网页上的入口点。每个页面只有一个平台。页面上运行的每个 Angular 应用程序所共有的服务(例如反射)都在其范围内绑定。当使用 PlatformBrowser
这样的平台工厂创建平台时,将隐式初始化此页面的平台;也可以通过调用 createPlatform()
函数来显式初始化此页面的平台。
The Angular platform is the entry point for Angular on a web page. Each page has exactly one platform. Services (such as reflection) which are common to every Angular application running on the page are bound in its scope. A page's platform is initialized implicitly when a platform is created using a platform factory such as PlatformBrowser
, or explicitly by calling the createPlatform()
function.
class PlatformRef {
injector: Injector
destroyed
bootstrapModuleFactory<M>(moduleFactory: NgModuleFactory<M>, options?: BootstrapOptions): Promise<NgModuleRef<M>>
bootstrapModule<M>(moduleType: Type<M>, compilerOptions: (CompilerOptions & BootstrapOptions) | (CompilerOptions & BootstrapOptions)[] = []): Promise<NgModuleRef<M>>
onDestroy(callback: () => void): void
destroy()
}
属性
属性 | 说明 |
---|---|
injector: Injector | 只读 |
destroyed | 只读 |
方法
为给定的平台创建 Creates an instance of an | ||||||
参数
返回值
| ||||||
使用说明以下示例为浏览器平台创建 NgModule。 The following example creates the NgModule for a browser platform.
|
使用给定的运行时编译器为给定的平台创建 Creates an instance of an | ||||||
参数
返回值
| ||||||
使用说明简单的例子Simple Example
|
注册销毁平台时要调用的监听器。 Registers a listener to be called when the platform is destroyed. |
销毁页面上的当前 Angular 平台和所有 Angular 应用程序。销毁在平台上注册的所有模块和监听器。 Destroys the current Angular platform and all Angular applications on the page. Destroys all modules and listeners registered with the platform. |
参数没有参数。 |