未捕获错误:无法解析PushObject的所有参数:(?)

时间:2017-10-14 08:00:04

标签: angular typescript ionic2 ionic3

当我在android上运行时发生了这个错误。

我正在使用@ ionic-native / push从我的nodejs服务器接收push noti。 这是我的配置: Component.ts:

initPushNotification() {
    const options: PushOptions = {
      android: {},
      ios: {
          alert: 'true',
          badge: true,
          sound: 'false'
      },
      windows: {},
      browser: {
          pushServiceURL: 'http://push.api.phonegap.com/v1/push'
      }
   };
    const pushObject: PushObject = this.push.init(options);

    pushObject.subscribe('topic').then(() => {
      console.log('subscribe success to topic')
    }).catch((e) => {
      console.log(e)
    })

    pushObject.on('registration').subscribe((data: any) => {
      console.log('device token -> ' + data.registrationId);
      //TODO - send device token to server
    });

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

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

我的app.modules.ts:

import { Push, PushObject } from '@ionic-native/push';

providers: [
...
    Push, PushObject,
...]

任何人都可以帮助我吗?

1 个答案:

答案 0 :(得分:4)

不要在提供者数组中包含PushObject,只包括Push类(因为那是提供者):

import { Push } from '@ionic-native/push';

providers: [
...
    Push,
...]