0

所以我使用这个插件:http://ngcordova.com/docs/plugins/pushNotificationsV5/这是cordovaPushV5,我试图让我的设备令牌发送到我的nodejs服务器。这里是我的代码:ngCordova错误保持发生

angular.module('starter', ['ionic', 'ngCordova']) 
 

 
.run(function($http, $cordovaPushV5) { 
 

 
    var options = { 
 
    \t android: { 
 
    \t senderID: "12345679" 
 
    \t }, 
 
    ios: { 
 
     alert: "true", 
 
     badge: "true", 
 
     sound: "true" 
 
    }, 
 
    windows: {} 
 
    }; 
 
    
 
    // initialize 
 
    $cordovaPushV5.initialize(options).then(function() { 
 
    // start listening for new notifications 
 
    $cordovaPushV5.onNotification(); 
 
    // start listening for errors 
 
    $cordovaPushV5.onError(); 
 
    
 
    // register to get registrationId 
 
    $cordovaPushV5.register().then(function(data) { 
 
     // `data.registrationId` save it somewhere; 
 
    }) 
 
    }); 
 
    
 
    // triggered every time notification received 
 
    $rootScope.$on('$cordovaPushV5:notificationReceived', function(event, data){ 
 
    // data.message, 
 
    // data.title, 
 
    // data.count, 
 
    // data.sound, 
 
    // data.image, 
 
    // data.additionalData 
 
    }); 
 

 
    // triggered every time error occurs 
 
    $rootScope.$on('$cordovaPushV5:errorOcurred', function(event, e){ 
 
    // e.message 
 
    }); 
 

 
});
<html> 
 
    <head> 
 
    <meta charset="utf-8"> 
 
    <meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no, width=device-width"> 
 
    <title></title> 
 

 
    <link href="lib/ionic/css/ionic.css" rel="stylesheet"> 
 
    <link href="css/style.css" rel="stylesheet"> 
 

 
    <!-- IF using Sass (run gulp sass first), then uncomment below and remove the CSS includes above 
 
    <link href="css/ionic.app.css" rel="stylesheet"> 
 
    --> 
 

 
    <!-- ionic/angularjs js --> 
 
    <script src="lib/ionic/js/ionic.bundle.js"></script> 
 

 
    <!-- cordova script (this will be a 404 during development) --> 
 
    <script src="lib/ngCordova/dist/ng-cordova.min.js"></script> 
 
    <script src="cordova.js"></script> 
 

 
    <!-- your app's js --> 
 
    <script src="js/app.js"></script> 
 
    </head> 
 
    <body ng-app="starter"> 
 

 
    <ion-pane> 
 
     <ion-header-bar class="bar-stable"> 
 
     <h1 class="title">Ionic Blank Starter</h1> 
 
     </ion-header-bar> 
 
     <ion-content> 
 
     </ion-content> 
 
    </ion-pane> 
 
    </body> 
 
</html>

当我运行它离子服务(浏览器)我得到这个控制台错误:的ReferenceError:找不到变量:PushNotification

有谁知道这是什么意思?

+0

您无法在浏览器中运行该模块。它必须在设备上运行。 –

回答

0

以上评论是100%正确的。该错误仅在浏览器中显示,因为此插件仅适用于设备