S. Dragomir S. Dragomir - 1 month ago 24
AngularJS Question

TypeError: Cannot read property 'local' of undefined at Object.schedule (ng-cordova.js:5042)

I have a problem scheduling local notifications with the ionic framework.

this is the angular module of my app.js

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

with a controller

.controller("ExampleController", function($scope, $ionicPlatform,$interval,$cordovaLocalNotification)

i try to create a notification with this method

scheduleInstantNotification = function () {
id: 1,
text: 'Value out of bound',
title: 'Anomaly'
}).then(function () {
alert("Instant Notification set");

when running on an android device i get this error message:

TypeError: Cannot read property 'local' of undefined
at Object.schedule (ng-cordova.js:5042)
at scheduleInstantNotification (app.js:138)
at app.js:64
at ionic.bundle.js:56230
at Object.ready (ionic.bundle.js:2140)
at Object.ready (ionic.bundle.js:56223)
at app.js:62
at callback (ionic.bundle.js:25611)
at Scope.$eval (ionic.bundle.js:30395)
at Scope.$digest (ionic.bundle.js:30211)

I suspect that this error comes from the ngCordova library the error comes from this code part of the library

schedule: function (options, scope) {
var q = $q.defer();
scope = scope || null;
$window.cordova.plugins.notification.local.schedule(options, function (result) {
}, scope);
return q.promise;

the $window.cordova.plugins.notification.local object is undefined.

Did I miss something in the controller?

adding the required plugin with:
cordova plugin add https://github.com/katzer/cordova-plugin-local-notifications.git

causes a compiler error when running

ionic build android

FAILURE: Build failed with an exception.
* What went wrong:
A problem occurred configuring root project 'android'.
> Could not resolve all dependencies for configuration ':_debugCompile'.
> Could not find any matches for com.android.support:support-v4:+ as no versions of com.android.support:support-v4 are available.
Searched in the following locations:

Required by:

  • Try:
    Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.


You need to add the plugin with :

cordova plugin add https://github.com/katzer/cordova-plugin-local-notifications.git

as instructed on ngcordova documentation :


Be sure also to call any method from the plugin after $ionicPlatform.ready.

EDIT To your error when compiling with this plugin, please be sure to have Android Support Library installed with the Android SDK Manager.