尝试实现本地通知,结果出现以下错误:
类型错误:无法读取未定义的属性“通知”
有问题的代码是,
function(){
$ionicPlatform.ready(function() {
$cordovaLocalNotification.add({
id: '1',
message: "Push!!"
})
}, false);
return true
}
我从 ionic tabs 示例制作了应用程序。发生此调用的 Controller 看起来像
已更新
angular.module('starter.controllers', ['ionic','ngCordova'])
.controller('FriendsCtrl', function($scope, $ionicPlatform, $cordovaLocalNotification,Friends) {
index.html 看起来像
<!-- 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.js"></script>
<!-- your app's js -->
<script src="js/app.js"></script>
<script src="js/controllers.js"></script>
<script src="js/services.js"></script>
<script src="js/filters.js"></script>
<script src="cordova.js"></script>
更新
$ionicPlatform is not defined 已修复,真正的问题在于
TypeError:无法读取未定义的属性“通知”
最佳答案
You're facing this error because, $ionicPlatform is not available in the global scope of your application.
似乎您正在尝试在应用程序加载的第一个实例上运行某些东西。好吧,为什么不用 Angular 方式呢?/
angular.module("starter", ['ionic']).
run(function($rootScope, $location, $ionicPlatform, $state) {
$ionicPlatform.ready(function() {
$cordovaLocalNotification.add({
id: '1',
message: "Push!!"
})
}, false);
});
From the Docs :
Run blocks are the closest thing in Angular to the main method. A run block is the code which needs to run to kickstart the application. It is executed after all of the service have been configured and the injector has been created.
关于javascript - 类型错误 : Cannot read property 'notification' of undefined,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26856876/