This is the archived documentation for Angular v6. Please visit angular.io to see documentation for the current version of Angular.

PlatformRef

The Angular platform is the entry point for Angular on a web page. Each page has exactly one platform, and services (such as reflection) which are common to every Angular application running on the page are bound in its scope.

See more...

      
      interface PlatformRef {
  injector: Injector
  destroyed
  bootstrapModuleFactory<M>(moduleFactory: NgModuleFactory<M>, options?: BootstrapOptions): Promise<NgModuleRef<M>>
  bootstrapModule<M>(moduleType: Type<M>, compilerOptions: (CompilerOptions & BootstrapOptions) | Array<CompilerOptions & BootstrapOptions> = []): Promise<NgModuleRef<M>>
  onDestroy(callback: () => void): void
  destroy()
}
    

Description

A page's platform is initialized implicitly when a platform is created via a platform factory (e.g. platformBrowser), or explicitly by calling the createPlatform function.

Properties

Property Description
injector: Injector Read-only.

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

destroyed Read-only.

Methods

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

Parameters

moduleFactory

Type: NgModuleFactory.

options

Type: BootstrapOptions.

Optional. Default is undefined.

Returns

Promise<NgModuleRef<M>>

Simple Example

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);
      
      
  1. my_module.ts:
  2.  
  3. @NgModule({
  4. imports: [BrowserModule]
  5. })
  6. class MyModule {}
  7.  
  8. main.ts:
  9. import {MyModuleNgFactory} from './my_module.ngfactory';
  10. import {platformBrowser} from '@angular/platform-browser';
  11.  
  12. 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) | Array<CompilerOptions & BootstrapOptions> = []): Promise<NgModuleRef<M>>
      
      bootstrapModule<M>(moduleType: Type<M>, compilerOptions: (CompilerOptions & BootstrapOptions) | Array<CompilerOptions & BootstrapOptions> = []): Promise<NgModuleRef<M>>
    

Parameters

moduleType

Type: Type.

compilerOptions

Type: (CompilerOptions & BootstrapOptions) | Array.

Optional. Default is [].

Returns

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

Register a listener to be called when the platform is disposed.

onDestroy(callback: () => void): void
      
      onDestroy(callback: () => void): void
    

Parameters

callback

Type: () => void.

Returns

void

Destroy the Angular platform and all Angular applications on the page.

destroy()
      
      destroy()
    

Parameters

There are no parameters.