Complete the code to create a basic Angular component that runs on the client side.
import { Component } from '@angular/core'; @Component({ selector: 'app-root', template: `<h1>Hello from [1]!</h1>` }) export class AppComponent {}
The component runs in the client browser, so 'client' fits best here.
Complete the code to import the Angular Universal module for server-side rendering.
import { [1] } from '@angular/platform-server';
ServerModule is the Angular module used for server-side rendering with Angular Universal.
Fix the error in this Angular server app bootstrap code by completing the blank.
import { enableProdMode } from '@angular/core'; import { platformServer } from '@angular/platform-server'; import { AppServerModule } from './app/app.server.module'; if (process.env.NODE_ENV === 'production') { enableProdMode(); } platformServer().bootstrapModule([1]) .catch(err => console.error(err));
For server-side rendering, bootstrap the AppServerModule, not the client AppModule.
Fill both blanks to complete the Angular Universal express server setup for SSR.
import * as express from 'express'; import { ngExpressEngine } from '@nguniversal/express-engine'; import { AppServerModule } from './src/main.server'; const app = express(); app.engine('html', [1]({ bootstrap: [2] }));
ngExpressEngine is the engine function, and AppServerModule is the bootstrap module for SSR.
Fill all three blanks to complete the Angular component that detects if it runs on server or client.
import { Component, Inject, PLATFORM_ID } from '@angular/core'; import { isPlatformBrowser, isPlatformServer } from '@angular/common'; @Component({ selector: 'app-root', template: `<p>{{message}}</p>` }) export class AppComponent { message = ''; constructor(@Inject(PLATFORM_ID) private platformId: Object) { if ([1](this.platformId)) { this.message = 'Running on [2]'; } else if ([3](this.platformId)) { this.message = 'Running on server'; } } }
Use isPlatformBrowser to check client, isPlatformServer to check server, and the message reflects that.