填写这份《一分钟调查》,帮我们(开发组)做得更好!去填写Home

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只读

检索平台 Injector,该平台是页面上每个 Angular 应用程序的父注入器,并提供单例提供者。

Retrieves the platform Injector, which is the parent injector for every Angular application on the page and provides singleton providers.

destroyed只读

方法

为给定的平台创建 @NgModule 的实例,以进行离线编译。

Creates an instance of an @NgModule for the given platform for offline compilation.

      
      bootstrapModuleFactory<M>(moduleFactory: NgModuleFactory<M>, options?: BootstrapOptions): Promise<NgModuleRef<M>>
    
参数
moduleFactory NgModuleFactory
options BootstrapOptions
可选. 默认值是 `undefined`.
返回值

Promise<NgModuleRef<M>>

使用说明

以下示例为浏览器平台创建 NgModule。

The following example creates the NgModule for a browser platform.

      
      my_module.ts:

@NgModule({
  imports: [BrowserModule]
})
class MyModule {}

main.ts:
import {MyModuleNgFactory} from './my_module.ngfactory';
import {platformBrowser} from '@angular/platform-browser';

let moduleRef = platformBrowser().bootstrapModuleFactory(MyModuleNgFactory);
    

使用给定的运行时编译器为给定的平台创建 @NgModule 的实例。

Creates an instance of an @NgModule for a given platform using the given runtime compiler.

      
      bootstrapModule<M>(moduleType: Type<M>, compilerOptions: (CompilerOptions & BootstrapOptions) | (CompilerOptions & BootstrapOptions)[] = []): Promise<NgModuleRef<M>>
    
参数
moduleType Type
compilerOptions (CompilerOptions & BootstrapOptions) | (CompilerOptions & BootstrapOptions)[]
可选. 默认值是 `[]`.
返回值

Promise<NgModuleRef<M>>

使用说明

简单的例子
Simple Example
      
      @NgModule({
  imports: [BrowserModule]
})
class MyModule {}

let moduleRef = platformBrowser().bootstrapModule(MyModule);
    

注册销毁平台时要调用的监听器。

Registers a listener to be called when the platform is destroyed.

      
      onDestroy(callback: () => void): void
    
参数
callback () => void
返回值

void

销毁页面上的当前 Angular 平台和所有 Angular 应用程序。销毁在平台上注册的所有模块和监听器。

Destroys the current Angular platform and all Angular applications on the page. Destroys all modules and listeners registered with the platform.

      
      destroy()
    
参数

没有参数。