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

PlatformRef

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.

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

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

destroyed只读

方法

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

bootstrapModuleFactory<M>(moduleFactory: NgModuleFactory<M>, options?: BootstrapOptions): Promise<NgModuleRef<M>>
      
      bootstrapModuleFactory<M>(moduleFactory: NgModuleFactory<M>, options?: BootstrapOptions): Promise<NgModuleRef<M>>
    
参数
moduleFactory NgModuleFactory
options BootstrapOptions

可选. 默认值是 undefined.

返回值

Promise<NgModuleRef<M>>

使用说明

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);
      
      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);
    

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>>
      
      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);
      
      @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
      
      onDestroy(callback: () => void): void
    
参数
callback () => void
返回值

void

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

destroy()
      
      destroy()
    
参数

没有参数。