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

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

我在使用 ionic 框架安排本地通知时遇到问题。

这是我的app.js

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

带控制器

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

我尝试使用此方法创建通知

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

当 运行 在 android 设备上时,我收到此错误消息:

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)

我怀疑这个错误来自 ngCordova 库错误来自库的这个代码部分

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

$window.cordova.plugins.notification.local 对象未定义。

我是不是漏掉了控制器里的东西?

编辑 添加所需的插件: cordova 插件添加 https://github.com/katzer/cordova-plugin-local-notifications.git

在运行

时导致编译器错误
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:

     https://repo1.maven.org/maven2/com/android/support/support-v4/maven-metadata.xml
     https://repo1.maven.org/maven2/com/android/support/support-v4/
     https://jcenter.bintray.com/com/android/support/support-v4/maven-metadata.xml
     https://jcenter.bintray.com/com/android/support/support-v4/
 Required by:
     :android:unspecified

您需要添加插件:

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

按照 ngcordova 文档中的说明:

http://ngcordova.com/docs/plugins/localNotification/

还要确保在 $ionicPlatform.ready 之后调用插件中的任何方法。

编辑 对于使用此插件编译时出现的错误,请确保使用 Android SDK 管理器安装了 Android 支持库。