angular / 14.0.0 / api / platform-server / renderapplication.html /

renderApplication

function developer preview

Bootstraps an instance of an Angular application and renders it to a string.

See more...

renderApplication<T>(rootComponent: Type<T>, options: { appId: string; document?: string; url?: string; providers?: (Provider | ImportedNgModuleProviders)[]; platformProviders?: Provider[]; }): Promise<string>

Parameters
rootComponent Type<T>

A reference to a Standalone Component that should be rendered.

options object

Additional configuration for the render operation:

  • appId - a string identifier of this application. The appId is used to prefix all server-generated stylings and state keys of the application in TransferState use-cases.
  • document - the full document HTML of the page to render, as a string.
  • url - the URL for the current render request.
  • providers - set of application level providers for the current render request.
  • platformProviders - the platform level providers for the current render request.
Returns

Promise<string>: A Promise, that returns serialized (to a string) rendered page, once resolved.

Description

Note: the root component passed into this function must be a standalone one (should have the standalone: true flag in the @Component decorator config).

@Component({
  standalone: true,
  template: 'Hello world!'
})
class RootComponent {}

const output: string = await renderApplication(RootComponent, {appId: 'server-app'});

© 2010–2022 Google, Inc.
Licensed under the Creative Commons Attribution License 4.0.
https://angular.io/api/platform-server/renderApplication