Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Uncaught (in promise): Error: StaticInjectorError[SwPush]: #4

Open
dineshvasan opened this issue Nov 14, 2017 · 5 comments
Open

Uncaught (in promise): Error: StaticInjectorError[SwPush]: #4

dineshvasan opened this issue Nov 14, 2017 · 5 comments

Comments

@dineshvasan
Copy link

Wow Awesome Bro for sharing your knowledge in Angular 5 using PWA.
I have issue in SwPush and i have attached screen shot,kindly find the attachment
Can you share me the simple example of source code while click the button option it will show the notification using swPush in Angular 5 with easy example. Kindly do the needful Bro.

This is my Mail ID dineshvasanmca@gmail.com

swangular5 - google chrome

@marlonwanger
Copy link

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

@dineshvasan
Copy link
Author

dineshvasan commented Nov 17, 2017

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);
})

}

@kangw3n
Copy link

kangw3n commented Nov 29, 2017

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

@dineshvasan
Copy link
Author

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

@allfayn
Copy link

allfayn commented Nov 30, 2017

Use Injector

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants