首页 > 解决方案 > 导入 Push 后开始出现错误“无法解析 myApp 的所有参数”

问题描述

问候,如标题所示,我的问题非常简单,在我尝试导入推送通知后,我的“@Component({})”开始给我错误,当我将鼠标悬停在插入推送导入的注入构造函数上时,我得到了出现以下错误“不能使用命名空间‘Push’作为类型。”

这是一个打印屏幕:https ://imgur.com/a/SXIrXjf

还有一个:https ://imgur.com/a/gTNRDdL

最后这是我的代码:

app.component.ts

import { Component } from '@angular/core';
import { Platform } from 'ionic-angular';
import { StatusBar } from '@ionic-native/status-bar';
import { SplashScreen } from '@ionic-native/splash-screen';
import { Push, PushObject, PushOptions } from '@ionic-native/push';
import { HomePage } from '../pages/home/home';
@Component({
  templateUrl: 'app.html'
})
export class MyApp {
  rootPage:any = HomePage;

  constructor(platform: Platform, statusBar: StatusBar, splashScreen: SplashScreen, private push: Push) {
    platform.ready().then(() => {
      // Okay, so the platform is ready and our plugins are available.
      // Here you can do any higher level native things you might need.
      statusBar.styleDefault();
      splashScreen.hide();
      this.pushSetup();

    });
  }

  pushSetup(){
    const options: PushOptions = {
      android: {
        senderID: '781594090050'
      },
      ios: {
          alert: 'true',
          badge: true,
          sound: 'false'
      }
   };

    const pushObject: PushObject = this.push.init(options);


    pushObject.on('notification').subscribe((notification: any) => console.log('Received a notification', notification));

    pushObject.on('registration').subscribe((registration: any) => console.log('Device registered', registration));

    pushObject.on('error').subscribe(error => console.error('Error with Push plugin', error));
  }

}

app.module.ts

import { BrowserModule } from '@angular/platform-browser';
import { ErrorHandler, NgModule } from '@angular/core';
import { IonicApp, IonicErrorHandler, IonicModule } from 'ionic-angular';
import { SplashScreen } from '@ionic-native/splash-screen';
import { StatusBar } from '@ionic-native/status-bar';

import { MyApp } from './app.component';
import { HomePage } from '../pages/home/home';
import { Push } from '@ionic-native/push';

@NgModule({
  declarations: [
    MyApp,
    HomePage
  ],
  imports: [
    BrowserModule,
    IonicModule.forRoot(MyApp)
  ],
  bootstrap: [IonicApp],
  entryComponents: [
    MyApp,
    HomePage
  ],
  providers: [
    StatusBar,
    SplashScreen,
    Push,
    {provide: ErrorHandler, useClass: IonicErrorHandler}
  ]
})
export class AppModule {}

我该如何解决?请帮忙

标签: angularfirebaseionic-frameworkfirebase-cloud-messaging

解决方案


要使用推送插件,您必须运行以下命令

ionic cordova plugin add phonegap-plugin-push
npm install @ionic-native/push

运行这些命令后重新启动您的离子服务实例


推荐阅读