Я знаю, что существует множество потоков для подобных ошибок, но ни одно из опробованных мной решений пока не работает. Я получаю сообщение об ошибке в notification.component.ts
: «Не могу разрешить все параметры для NotificationComponent (?)», И, похоже, это относится к SwPu sh, который я импортирую. Я пробовал добавить изменение import { SwPush } from '@angular/service-worker';
на import { SwPush } from '@angular/service-worker/service-worker.ts';
, поскольку VSCode предлагает это. Ошибка исчезает в VSCode, но тогда SwPu sh, похоже, не работает или не распознает, когда я его использую.
notification.component.ts
import { Component, OnInit } from '@angular/core';
// not sure if this service worker import is correct
import { SwPush } from '@angular/service-worker';
@Component({
selector: 'app-notification',
templateUrl: './notification.component.html',
styleUrls: ['./notification.component.css'],
})
export class NotificationComponent implements OnInit {
VAPID_PUBLIC =
'XXXXXXXX';
constructor(swPush: SwPush) {
if (swPush.isEnabled) {
swPush
.requestSubscription({
serverPublicKey: this.VAPID_PUBLIC,
})
.then((subscription) => {
// send subscription to the server
})
.catch(console.error);
}
}
ngOnInit() {}
}
package.json
{
"name": "staff-angular",
"version": "0.0.0",
"scripts": {
"ng": "ng",
"start": "ng serve",
"build": "ng build",
"test": "ng test",
"lint": "ng lint",
"e2e": "ng e2e"
},
"private": true,
"dependencies": {
"@angular/animations": "~8.2.14",
"@angular/common": "~8.2.14",
"@angular/compiler": "~8.2.14",
"@angular/core": "~8.2.14",
"@angular/forms": "~8.2.14",
"@angular/platform-browser": "~8.2.14",
"@angular/platform-browser-dynamic": "~8.2.14",
"@angular/pwa": "^0.901.4",
"@angular/router": "~8.2.14",
"@angular/service-worker": "~8.2.14",
"rxjs": "~6.4.0",
"socket.io": "^2.3.0",
"socket.io-client": "^2.3.0",
"tslib": "^1.11.2",
"web-push": "^3.4.3",
"zone.js": "~0.9.1"
},
"devDependencies": {
"@angular-devkit/build-angular": "~0.803.19",
"@angular/cli": "~8.3.19",
"@angular/compiler-cli": "~8.2.14",
"@angular/language-service": "~8.2.14",
"@types/jasmine": "~3.3.8",
"@types/jasminewd2": "~2.0.3",
"@types/node": "~8.9.4",
"codelyzer": "^5.0.0",
"jasmine-core": "~3.4.0",
"jasmine-spec-reporter": "~4.2.1",
"karma": "~4.1.0",
"karma-chrome-launcher": "~2.2.0",
"karma-coverage-istanbul-reporter": "~2.0.1",
"karma-jasmine": "~2.0.1",
"karma-jasmine-html-reporter": "^1.4.0",
"protractor": "^5.4.4",
"ts-node": "~7.0.0",
"tslint": "~5.15.0",
"typescript": "~3.5.3"
}
}
app.module.ts
import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { AppRoutingModule } from './app-routing.module';
import { AppComponent } from './app.component';
import { HttpClientModule } from '@angular/common/http';
import { FormsModule } from '@angular/forms';
import { UserComponent } from './user/user/user.component';
import { OverviewComponent } from './messenger/overview/overview.component';
import { CompanyProfileComponent } from './user/company-profile/company-profile.component';
import { ServiceWorkerModule } from '@angular/service-worker';
import { NotificationComponent } from './user/notification/notification.component';
import { environment } from '../environments/environment';
@NgModule({
declarations: [
AppComponent,
UserComponent,
OverviewComponent,
CompanyProfileComponent,
NotificationComponent
],
imports: [
BrowserModule,
AppRoutingModule,
HttpClientModule,
FormsModule,
ServiceWorkerModule.register('ngsw-worker.js', { enabled: environment.production })
],
providers: [],
bootstrap: [AppComponent]
})
export class AppModule { }