类型错误:无法读取的未定义的属性'通知' [英] TypeError: Cannot read property 'notification' of undefined

查看:1825
本文介绍了类型错误:无法读取的未定义的属性'通知'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

试图实现与下面的错误,结果本地通知:

类型错误:无法读取的未定义的属性'通知'

code的问题是,

 函数(){
    $ ionicPlatform.ready(函数(){
        $ cordovaLocalNotification.add({
            编号:'1',
            消息:推!
        })
    },FALSE);
    返回true
    }

我从离子标签的例子应用程序。控制器在此调用正在发生的事情看起来像

更新

angular.module('starter.controllers',['离子','ngCordova'])
     .controller('FriendsCtrl',函数($范围,$ ionicPlatform,$ cordovaLocalNotification,友){

的index.html 看起来

 <! - 离子/ angularjs JS  - >
<脚本SRC =LIB /离子/ JS / ionic.bundle.js>< / SCRIPT><! - 科尔多瓦脚本(这将是开发过程中一个404) - GT;
<脚本SRC =LIB / ngCordova /距离/ NG-cordova.js>< / SCRIPT><! - 您的应用程序的JS - >
<脚本SRC =JS / app.js>< / SCRIPT>
<脚本SRC =JS / controllers.js>< / SCRIPT>
<脚本SRC =JS / services.js>< / SCRIPT>
<脚本SRC =JS / filters.js>< / SCRIPT>
&所述; SCRIPT SRC =cordova.js>&下; /脚本>

更新
没有定义$ ionicPlatform已定,真正的问题在于
类型错误:无法读取的未定义的属性'通知'


解决方案

  

您遇到这个错误,因为$ ionicPlatform是不是在你的应用程序的全局范围内。


好像你正试图在其上运行的第一个实例的应用程序加载的东西。那么,为什么不去做呢角的方式?/

  angular.module(启动器,['离子'])。
    运行(函数($ rootScope,$位置$ ionicPlatform,$州){
        $ ionicPlatform.ready(函数(){
            $ cordovaLocalNotification.add({
                编号:'1',
                消息:推!
            })
        },FALSE);
    });


  

从文档:


  
  

运行块是角度的主要方法最接近。一个运行块是code这需要运行的kickstart应用程序。所有的服务都设定好后,执行和注射器已创建。


Trying to implement local notification with the following error as a result:

TypeError: Cannot read property 'notification' of undefined

Code in question is,

function(){ 
    $ionicPlatform.ready(function() {
        $cordovaLocalNotification.add({
            id: '1',
            message: "Push!!"
        })
    }, false);  
    return true
    }

I made the app from ionic tabs example. Controller in which this call is happening looks like

Updated

angular.module('starter.controllers', ['ionic','ngCordova']) .controller('FriendsCtrl', function($scope, $ionicPlatform, $cordovaLocalNotification,Friends) {

index.html looks like

<!-- 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>

UPDATE $ionicPlatform is not defined has been fixed, real issue lies in TypeError: Cannot read property 'notification' of undefined

解决方案

You're facing this error because, $ionicPlatform is not available in the global scope of your application.

Seems like you're trying to run something on the very first instance the application loads. Well, why not do it the angular way ?/

    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.

这篇关于类型错误:无法读取的未定义的属性'通知'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆