How to use the @angular/service-worker.SwPush.requestSubscription function in @angular/service-worker

To help you get started, we’ve selected a few @angular/service-worker examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github rdrahul / AngularPushNotification / src / app / app.component.ts View on Github external
constructor( private SwPush : SwPush , private pushNotification : PushNotificationService ){


    //check if the browser supports service workers
    if( SwPush.isEnabled){

      SwPush.requestSubscription({
        serverPublicKey :  VAPID_PUBLIC
      })
      .then( subscription => {
        
        //send subsription to server
        this.pushNotification.SendSubsriptionToService(subscription).subscribe() ;

      })
      .catch(console.error);
    
    }
  }
}