Search icon CANCEL
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Server-Side Enterprise Development with Angular

You're reading from   Server-Side Enterprise Development with Angular Use Angular Universal to pre-render your web pages, improving SEO and application UX

Arrow left icon
Product type Paperback
Published in Nov 2018
Publisher
ISBN-13 9781789806267
Length 142 pages
Edition 1st Edition
Languages
Tools
Concepts
Arrow right icon
Author (1):
Arrow left icon
Bram Borggreve Bram Borggreve
Author Profile Icon Bram Borggreve
Bram Borggreve
Arrow right icon
View More author details
Toc

3. Service Workers

Activity 10: Communicating with the Service Worker

Solution:

  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
lock icon The rest of the chapter is locked
arrow left Previous Section
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at ₹800/month. Cancel anytime