Cookies concent notice

This site uses cookies from Google to deliver its services and to analyze traffic.
Learn more
Skip to main content
This site is no longer updated.Head to Angular.devHome
/

This is the archived documentation for Angular v17. Please visit angular.dev to see this page 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. 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() }

Provided in

  • 'platform'

Properties

Property Description
injector: Injector Read-Only

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

destroyed Read-Only

Indicates whether this instance was destroyed.

Methods

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

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

Deprecated Passing NgModule factories as the PlatformRef.bootstrapModuleFactory function argument is deprecated. Use the PlatformRef.bootstrapModule API instead.

Parameters
moduleFactory NgModuleFactory<M>
options BootstrapOptions

Optional. Default is undefined.

Returns

Promise<NgModuleRef<M>>

Creates an instance of an @NgModule for a given platform.

      
      bootstrapModule<M>(moduleType: Type<M>, compilerOptions: (CompilerOptions & BootstrapOptions) | (CompilerOptions & BootstrapOptions)[] = []): Promise<NgModuleRef<M>>
    
Parameters
moduleType Type<M>
compilerOptions (CompilerOptions & BootstrapOptions) | (CompilerOptions & BootstrapOptions)[]

Optional. Default is [].

Returns

Promise<NgModuleRef<M>>

Usage Notes

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
    
Parameters
callback () => void
Returns

void

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

      
      destroy()
    
Parameters

There are no parameters.