PlatformRef

export class PlatformRef

exported from angular2/core defined in angular2/src/core/application_ref.ts (line 138)

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.

A page's platform is initialized implicitly when bootstrap() is called, or explicitly by calling platform().

Members

registerDisposeListener(dispose: () => void) : void

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

injector : Injector

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

application(providers: Array<Type | Provider | any[]>) : ApplicationRef

Instantiate a new Angular application on the page.

What is an application?

Each Angular application has its own zone, change detection, compiler, renderer, and other framework components. An application hosts one or more root components, which can be initialized via ApplicationRef.bootstrap().

Application Providers

Angular applications require numerous providers to be properly instantiated. When using application() to create a new app on the page, these providers must be provided. Fortunately, there are helper functions to configure typical providers, as shown in the example below.

#

@Component({selector: 'my-app', template: 'Hello World'}) class MyApp { } var app = platform(BROWSER_PROVIDERS).application([BROWSER_APP_PROVIDERS, appProviders]); app.bootstrap(MyApp);

See Also

See the bootstrap documentation for more details.

asyncApplication(bindingFn: (zone: NgZone) => Promise<Array<Type | Provider | any[]>>, providers?: Array<Type | Provider | any[]>) : Promise<ApplicationRef>

Instantiate a new Angular application on the page, using providers which are only available asynchronously. One such use case is to initialize an application running in a web worker.

Usage

bindingFn is a function that will be called in the new application's zone. It should return a Promise to a list of providers to be used for the new application. Once this promise resolves, the application will be constructed in the same manner as a normal application().

dispose() : void

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