3. Service Workers
Activity 10: Communicating with the Service Worker
Solution:
- Open the
src/app/app.module.tsfile in your editor. - Import
SwPushandSwUpdatefrom@angular/service-worker:import { SwPush, SwUpdate } from '@angular/service-worker'; - Add a constructor and inject
SwPushandSwUpdate:constructor(public push: SwPush, private updates: SwUpdate) { } - 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: