3. Service Workers
Activity 10: Communicating with the Service Worker
Solution:
- Open the
src/app/app.module.ts
file in your editor. - Import
SwPush
andSwUpdate
from@angular/service-worker
:import { SwPush, SwUpdate } from '@angular/service-worker';
- Add a constructor and inject
SwPush
andSwUpdate
: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: