Comments (5)
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.
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.
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.
Bro can u share the simple example of Push Notification without hitting on server. this so urgent . Kindly do the needful
from pwatter.
Use Injector
if (environment.production) {
const swpush = this.injector.get(SwPush);
// code use swpush
}
from pwatter.
Related Issues (8)
- Question about Datagroups
- Service-worker custom plugin HOT 3
- Mock SwPush and SwUpdate in development HOT 7
- Property 'take' does not exist on type 'Observable<PushSubscription>' HOT 1
- How to create Service Worker in Development Mode HOT 1
- Service Worker postmessage in Angular 5 how to do it. Kindy Share any the sample Example of Postmessage
- SwPush Issues Angular 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from pwatter.