亲爱的我想使用angular5订阅Chrome推送服务。我详细介绍了文件以及在生产中出现的错误
我的html
<button class="button button-primary" (click)="subscribeToNotifications()">
Subscribe
</button>
我的.ts
import {SwPush} from "@angular/service-worker";
readonly VAPID_PUBLIC_KEY = "BKbm4zVsmx0sJg2IUNNwLYYPsDvYMS_U1GonPKzG_S9_1oe-OWyK_justdEpGDx_UbyYRMwK3mqoEfbTalrECWs";
sub: PushSubscription;
public subscribeToNotifications() {
this.swPush.requestSubscription({
serverPublicKey: this.VAPID_PUBLIC_KEY
})
.then(sub => {
this.sub = sub;
console.log("Notification Subscription: ", sub);
})
.catch(err => console.error("Could not subscribe to notifications", err));
}
我的模块
ServiceWorkerModule.register('/ngsw-worker.js', { enabled: true }),
然后返回