1

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

1 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

7 Comments

im new to angular, where would I throw that code? right now I have it in the controller being $scope.push = push_cmd()
No platform is found, i didnt pass it through, but now its TypeError: Cannot read property 'notification' of undefined
Write your run block like this : run(function($rootScope, $location, $ionicPlatform, $state, $cordovaLocalNotification) {.. And if it doesn't works, please share your code block and console error.
FYI,i am throwing that commmand in a controller not a run, or is that wrong?
Error comes from ng-cordova.js in line $window.plugin.notification.local.add( Clearly something isnt loaded when error is Uncaught TypeError: Cannot read property 'notification' of undefined
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.