How to use the @angular/platform-server.platformServer function in @angular/platform-server

To help you get started, we’ve selected a few @angular/platform-server examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github dimangulov / expenses / src / Expenses / Client / polyfills / temporary-aspnetcore-engine.ts View on Github external
useValue: {
              document: options.appSelector,
              url: options.request.url
            }
          },
          {
            provide: ORIGIN_URL,
            useValue: options.request.origin
          }, {
            provide: REQUEST,
            useValue: options.request.data.request
          }
        ]
      );

      const platform = platformServer(extraProviders);

      getFactory(moduleOrFactory, compiler)
        .then((factory: NgModuleFactory<{}>) => {

          return platform.bootstrapModuleFactory(factory).then((moduleRef: NgModuleRef<{}>) => {

            const state: PlatformState = moduleRef.injector.get(PlatformState);
            const appRef: ApplicationRef = moduleRef.injector.get(ApplicationRef);

            appRef.isStable
              .filter((isStable: boolean) => isStable)
              .first()
              .subscribe((stable) => {

                // Fire the TransferState Cache
                const bootstrap = moduleRef.instance['ngOnBootstrap'];
github Independer / ind-angular-starter / src / shared / ssr / server-only / aspnetcore-engine-temp.ts View on Github external
document: options.appSelector,
              url: options.request.url
            }
          },
          {
            provide: ORIGIN_URL,
            useValue: options.request.origin
          },
          {
            provide: APP_BASE_HREF,
            useValue: options.request.baseUrl
          }
        ]
      );

      const platform = platformServer(extraProviders);

      getFactory(moduleOrFactory, compiler)
        .then((factory: NgModuleFactory<{}>) => {

          return platform.bootstrapModuleFactory(factory).then((moduleRef: NgModuleRef<{}>) => {

            const state: PlatformState = moduleRef.injector.get(PlatformState);
            const appRef: ApplicationRef = moduleRef.injector.get(ApplicationRef);

            appRef.isStable
              .filter((isStable: boolean) => isStable)
              .first()
              .subscribe((stable: any) => {

                // Fire the SsrState Cache
                const bootstrap = (moduleRef.instance as any)['ngOnBootstrap'];
github TrilonIO / aspnetcore-angular-universal / ClientApp / polyfills / temporary-aspnetcore-engine.ts View on Github external
useValue: {
              document: options.appSelector,
              url: options.request.url
            }
          },
          {
            provide: ORIGIN_URL,
            useValue: options.request.origin
          }, {
            provide: REQUEST,
            useValue: options.request.data.request
          }
        ]
      );

      const platform = platformServer(extraProviders);

      getFactory(moduleOrFactory, compiler)
        .then((factory: NgModuleFactory<{}>) => {

          return platform.bootstrapModuleFactory(factory).then((moduleRef: NgModuleRef<{}>) => {

            const state: PlatformState = moduleRef.injector.get(PlatformState);
            const appRef: ApplicationRef = moduleRef.injector.get(ApplicationRef);

            appRef.isStable
              .filter((isStable: boolean) => isStable)
              .first()
              .subscribe((stable) => {

                // Fire the TransferState Cache
                const bootstrap = moduleRef.instance['ngOnBootstrap'];
github angular / universal / modules / common / ls-routes / src / ls-routes.ts View on Github external
export function lsRoutes(
  serverFactory: NgModuleFactory,
  lazyModuleMap?: any
) {
  const ngZone = new NgZone({ enableLongStackTrace: false });
  const rootInjector = Injector.create(
    [
      { provide: NgZone, useValue: ngZone },
      provideModuleMap(lazyModuleMap)
    ],
    platformServer().injector
  );
  const moduleRef = serverFactory.create(rootInjector);
  loader = moduleRef.injector.get(NgModuleFactoryLoader);
  return Promise.all(createModule(serverFactory, rootInjector))
    .then(routes => {
        return flattenArray(flattenRouteToPath(routes));
    });
}
github gregmagolan / abc-demo-build-with-aot-universal / src / server / main.server.ts View on Github external
function getDoc(filePath: string, url: string): Observable {
  const index = fs.readFileSync(filePath).toString();
  const platform =
    platformServer([{ provide: INITIAL_CONFIG, useValue: { document: index, url: url } }]);
  return Observable.fromPromise(platform.bootstrapModuleFactory(ServerAppModuleNgFactory))
    .switchMap((moduleRef) => {
      const applicationRef: ApplicationRef = moduleRef.injector.get(ApplicationRef);
      return applicationRef.isStable;
    })
    .first((stable) => stable === true)
    .map(() => platform.injector.get(PlatformState).renderToString())
    .finally(() => platform.destroy());
}
github sharpangles / platform / libraries / platform-angular / src / features / angular_platform_server_feature.ts View on Github external
protected async bootstrap(rootModule: any) {
        platformServer().bootstrapModuleFactory(rootModule);
    }
}