Giter Club home page Giter Club logo

Comments (5)

marlonwanger avatar marlonwanger commented on June 9, 2024

Hello, did you register the ServiceWorkerModule in app.module?
are you running the app in dev or prod mode?
if I'm not mistaken, this problem happens because you're running in dev mode

from pwatter.

dineshvasan avatar dineshvasan commented on June 9, 2024

How to run the app in dev mode?
Yes Service Worker is working fine on Prod mode and i need simple example of Push Notification without hitting on server. i got error on dev mode in the above image

Source Code

export class PushNotificationComponent implements OnInit {

private VAPID_PUBLIC_KEY: string;
constructor(private swPush: SwPush,private configService: GlobalconfigService) { }

ngOnInit() {
this.VAPID_PUBLIC_KEY = this.configService.get('VAPID_PUBLIC_KEY');
}
tweets=[];
message: any ={"notification":{"title":"Ranjeet Kumar","actions":[{"action":"opentweet","title":"Open tweet"}],"body":"The latest The Top Javascript Blogs Daily! https://t.co/o3PSNkk9Di Thanks to @LifeWithKathy #makeyourownlane","dir":"auto","icon":"https://pbs.twimg.com/profile_images/854195961085734917/0X7AFONJ_normal.jpg","badge":"https://pbs.twimg.com/profile_images/854195961085734917/0X7AFONJ_normal.jpg","lang":"en","renotify":true,"requireInteraction":true,"tag":926796012340920300,"vibrate":[300,100,400],"data":{"url":"https://twitter.com/statuses/926796012340920321","created_at":"Sat Nov 04 12:59:23 +0000 2017","favorite_count":0,"retweet_count":0}}};

showPopupNotification(){

this.swPush.requestSubscription({
  serverPublicKey: this.VAPID_PUBLIC_KEY
})
.then(pushSubscription => {
  let notification = this.message['notification'];

  let body = {
    action: 'subscribe',
    subscription: pushSubscription
  }



})
.catch(err => {
  console.error(err);
})

}

from pwatter.

kangw3n avatar kangw3n commented on June 9, 2024

use @Optional decorator upon injection

https://angular.io/api/core/Optional

example:

import {Optional} from '@angular/core';

inside constructor:
`

@optional private swPush: SwPush

`,

Hope this will help

from pwatter.

dineshvasan avatar dineshvasan commented on June 9, 2024

Bro can u share the simple example of Push Notification without hitting on server. this so urgent . Kindly do the needful

from pwatter.

allfayn avatar allfayn commented on June 9, 2024

Use Injector

if (environment.production) {
      const swpush = this.injector.get(SwPush);
      // code use swpush
    }

from pwatter.

Related Issues (8)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.