作为标题的问候表明,当我尝试导入Push通知后,我的问题很简单,当我将鼠标悬停在插入的push导入的注入构造函数上时,我的'@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 {}
我该如何解决?请帮助
答案 0 :(得分:0)
要使用推插件,您必须运行以下命令
ionic cordova plugin add phonegap-plugin-push
npm install @ionic-native/push
运行这些命令后,重新启动离子服务实例