Book Image

Server-Side Enterprise Development with Angular

By : Bram Borggreve
Book Image

Server-Side Enterprise Development with Angular

By: Bram Borggreve

Overview of this book

With the help of Server-Side Enterprise Development with Angular, equip yourself with the skills required to create modern, progressive web applications that load quickly and efficiently. This fast-paced book is a great way to learn how to build an effective UX by using the new features of Angular 7 beta, without wasting efforts in searching for referrals. To start off, you'll install Angular CLI and set up a working environment, followed by learning to distinguish between the container and presentational components. You'll explore advanced concepts such as making requests to a REST API from an Angular application, creating a web server using Node.js and Express, and adding dynamic metadata. You'll also understand how to implement and configure a service worker using Angular PWA and deploy the server-side rendered app to the cloud. By the end of this book, you'll have developed skills to serve your users views that load instantly, while reaping all the SEO benefits of improved page indexing.
Table of Contents (5 chapters)

3. Service Workers

Activity 10: Communicating with the Service Worker


  1. Open the src/app/app.module.ts file in your editor.
  2. Import SwPush and SwUpdate from @angular/service-worker:
    import { SwPush, SwUpdate } from '@angular/service-worker';
  3. Add a constructor and inject SwPush and SwUpdate:
    constructor(public push: SwPush, private updates: SwUpdate) {
  4. Add the following lines in the constructor method:
    console.log('Push enabled: ', push.isEnabled);
    console.log('Updated enabled: ', updates.isEnabled);

Now when you create a new build of the app, you will see a message being printed in the console that tells the status of the SwPush and SwUpdate classes:

Figure 3.10: SwPush and SwUpdate messages in the console