@angular/platform-server

  • Version 22.0.6
  • Published
  • 1.7 MB
  • 2 dependencies
  • MIT license

Install

npm i @angular/platform-server
yarn add @angular/platform-server
pnpm add @angular/platform-server

Overview

Angular - library for using Angular in Node.js

Index

Variables

variable BEFORE_APP_SERIALIZED

const BEFORE_APP_SERIALIZED: InjectionToken<readonly (() => void | Promise<void>)[]>;
  • A function that will be executed when calling renderApplication or renderModule just before current platform state is rendered to string.

variable INITIAL_CONFIG

const INITIAL_CONFIG: InjectionToken<PlatformConfig>;
  • The DI token for setting the initial config for the platform.

variable ɵENABLE_DOM_EMULATION

const ɵENABLE_DOM_EMULATION: InjectionToken<boolean>;

    variable ɵINTERNAL_SERVER_PLATFORM_PROVIDERS

    const ɵINTERNAL_SERVER_PLATFORM_PROVIDERS: StaticProvider[];

      variable ɵSERVER_CONTEXT

      const ɵSERVER_CONTEXT: InjectionToken<string>;
      • An internal token that allows providing extra information about the server context (e.g. whether SSR or SSG was used). The value is a string and characters other than [a-zA-Z0-9-] are removed. See the default value in DEFAULT_SERVER_CONTEXT const.

      variable ɵSERVER_RENDER_PROVIDERS

      const ɵSERVER_RENDER_PROVIDERS: Provider[];

        variable VERSION

        const VERSION: Version;

        Functions

        function ɵisHostAllowed

        ɵisHostAllowed: (hostname: string, allowedHosts: ReadonlySet<string>) => boolean;
        • Checks if the hostname is allowed.

          Parameter hostname

          The hostname to check.

          Parameter allowedHosts

          A set of allowed hostnames.

          Returns

          true if the hostname is allowed, false otherwise. Used also in @angular/ssr.

        function ɵrenderInternal

        ɵrenderInternal: (
        platformRef: PlatformRef,
        applicationRef: ApplicationRef
        ) => Promise<string>;
        • Renders an Angular application to a string.

          Parameter platformRef

          Reference to the Angular platform.

          Parameter applicationRef

          Reference to the Angular application.

          Returns

          A promise that resolves to the rendered string.

        function platformServer

        platformServer: (extraProviders?: StaticProvider[] | undefined) => PlatformRef;
        • Creates a server-side instance of an Angular platform.

          This platform should be used when performing server-side rendering of an Angular application. Standalone applications can be bootstrapped on the server using the bootstrapApplication function from @angular/platform-browser. When using bootstrapApplication, the platformServer should be created first and passed to the bootstrap function using the BootstrapContext.

        function provideServerRendering

        provideServerRendering: (options?: {
        maxResponseBodySize: number;
        }) => EnvironmentProviders;
        • Sets up providers necessary to enable server rendering functionality for the application.

          Parameter options

          An object to configure the server providers. Currently supports the following options: - maxResponseBodySize: The maximum allowed response body size when using the Fetch API.

          Basic example of how you can add server support to your application:

          bootstrapApplication(AppComponent, {
          providers: [provideServerRendering()]
          });

          Returns

          A set of providers to setup the server.

        function renderApplication

        renderApplication: (
        bootstrap: (context: BootstrapContext) => Promise<ApplicationRef>,
        options: {
        document?: string | Document;
        url?: string;
        platformProviders?: Provider[];
        allowedHosts?: Readonly<string>[];
        }
        ) => Promise<string>;
        • Bootstraps an instance of an Angular application and renders it to a string.

          import { BootstrapContext, bootstrapApplication } from '@angular/platform-browser';
          import { renderApplication } from '@angular/platform-server';
          import { ApplicationConfig } from '@angular/core';
          import { AppComponent } from './app.component';
          const appConfig: ApplicationConfig = { providers: [...] };
          const bootstrap = (context: BootstrapContext) =>
          bootstrapApplication(AppComponent, config, context);
          const output = await renderApplication(bootstrap);

          Parameter bootstrap

          A method that when invoked returns a promise that returns an ApplicationRef instance once resolved. The method is invoked with an Injector instance that provides access to the platform-level dependency injection context.

          Parameter options

          Additional configuration for the render operation: - document - the document of the page to render, either as an HTML string or as a reference to the document instance. - url - the URL for the current render request. - platformProviders - the platform level providers for the current render request. - allowedHosts - the allowed hosts list for host validation in server-side rendering.

          Returns

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

        function renderModule

        renderModule: <T>(
        moduleType: Type<T>,
        options: {
        document?: string | Document;
        url?: string;
        extraProviders?: StaticProvider[];
        allowedHosts?: Readonly<string>[];
        }
        ) => Promise<string>;
        • Bootstraps an application using provided NgModule and serializes the page content to string.

          Parameter moduleType

          A reference to an NgModule that should be used for bootstrap.

          Parameter options

          Additional configuration for the render operation: - document - the document of the page to render, either as an HTML string or as a reference to the document instance. - url - the URL for the current render request. - extraProviders - set of platform level providers for the current render request. - allowedHosts - the allowed hosts list for host validation in server-side rendering.

        Classes

        class ɵDominoAdapter

        class DominoAdapter extends _BrowserDomAdapter {}
        • DOM Adapter for the server platform based on https://github.com/fgnass/domino.

        property supportsDOMEvents

        readonly supportsDOMEvents: boolean;

          method createHtmlDocument

          createHtmlDocument: () => Document;

            method dispatchEvent

            dispatchEvent: (el: Node, evt: any) => void;

              method getBaseHref

              getBaseHref: (doc: Document) => string;

                method getCookie

                getCookie: (name: string) => string;

                  method getDefaultDocument

                  getDefaultDocument: () => Document;

                    method getGlobalEventTarget

                    getGlobalEventTarget: (doc: Document, target: string) => EventTarget | null;
                    • Deprecated

                      No longer being used in Ivy code. To be removed in version 14.

                    method getUserAgent

                    getUserAgent: () => string;

                      method isElementNode

                      isElementNode: (node: any) => boolean;

                        method isShadowRoot

                        isShadowRoot: (node: any) => boolean;

                          method makeCurrent

                          static makeCurrent: () => void;

                            class PlatformState

                            class PlatformState {}
                            • Representation of the current platform state.

                            constructor

                            constructor(_doc: any);

                              property ɵfac

                              static ɵfac: i0.ɵɵFactoryDeclaration<PlatformState, never>;

                                property ɵprov

                                static ɵprov: i0.ɵɵInjectableDeclaration<PlatformState>;

                                  method getDocument

                                  getDocument: () => any;
                                  • Returns the current DOM state.

                                  method renderToString

                                  renderToString: () => string;
                                  • Renders the current state of the platform to string.

                                  class ServerModule

                                  class ServerModule {}
                                  • The ng module for the server.

                                  property ɵfac

                                  static ɵfac: i0.ɵɵFactoryDeclaration<ServerModule, never>;

                                    property ɵinj

                                    static ɵinj: i0.ɵɵInjectorDeclaration<ServerModule>;

                                      property ɵmod

                                      static ɵmod: i0.ɵɵNgModuleDeclaration<ServerModule, never, never, [any]>;

                                        Interfaces

                                        interface PlatformConfig

                                        interface PlatformConfig {}
                                        • Config object passed to initialize the platform.

                                        property document

                                        document?: string;
                                        • The initial DOM to use to bootstrap the server application. create a new DOM using Domino

                                        property url

                                        url?: string;
                                        • The URL for the current application state. This is used for initializing the platform's location. protocol, hostname, and port.

                                        Enums

                                        enum RuntimeErrorCode

                                        const enum RuntimeErrorCode {
                                        GET_COOKIE_NOT_IMPLEMENTED = 5700,
                                        INVALID_URL = 5701,
                                        PROTOCOL_RELATIVE_URL_NOT_ALLOWED = 5702,
                                        SUSPICIOUS_URL_CHANGE_ORIGIN = 5703,
                                        DISABLED_DOM_EMULATION_IN_NON_BROWSER = 5704,
                                        XHR_NOT_LOADED = 5705,
                                        HOST_NOT_ALLOWED = 5706,
                                        }
                                        • The list of error codes used in runtime code of the platform-server package. Reserved error code range: 5700-5800.

                                        member DISABLED_DOM_EMULATION_IN_NON_BROWSER

                                        DISABLED_DOM_EMULATION_IN_NON_BROWSER = 5704
                                          GET_COOKIE_NOT_IMPLEMENTED = 5700

                                            member HOST_NOT_ALLOWED

                                            HOST_NOT_ALLOWED = 5706

                                              member INVALID_URL

                                              INVALID_URL = 5701

                                                member PROTOCOL_RELATIVE_URL_NOT_ALLOWED

                                                PROTOCOL_RELATIVE_URL_NOT_ALLOWED = 5702

                                                  member SUSPICIOUS_URL_CHANGE_ORIGIN

                                                  SUSPICIOUS_URL_CHANGE_ORIGIN = 5703

                                                    member XHR_NOT_LOADED

                                                    XHR_NOT_LOADED = 5705

                                                      Package Files (1)

                                                      Dependencies (2)

                                                      Dev Dependencies (0)

                                                      No dev dependencies.

                                                      Peer Dependencies (5)

                                                      Badge

                                                      To add a badge like this onejsDocs.io badgeto your package's README, use the codes available below.

                                                      You may also use Shields.io to create a custom badge linking to https://www.jsdocs.io/package/@angular/platform-server.

                                                      • Markdown
                                                        [![jsDocs.io](https://img.shields.io/badge/jsDocs.io-reference-blue)](https://www.jsdocs.io/package/@angular/platform-server)
                                                      • HTML
                                                        <a href="https://www.jsdocs.io/package/@angular/platform-server"><img src="https://img.shields.io/badge/jsDocs.io-reference-blue" alt="jsDocs.io"></a>