2016-09-21 24 views
0

我有一個使用離子框架調度本地通知的問題。TypeError:無法讀取在Object.schedule undefined的屬性'local'(ng-cordova.js:5042)

這是我角模塊app.js

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對象是不確定的。

我錯過了控制器中的東西嗎?

編輯 添加所需的插件有: 科爾多瓦插件添加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 
  • 嘗試: 與--stacktrace選項獲取運行堆棧跟蹤。使用--info或--debug選項運行以獲取更多日誌輸出。
+0

我編輯了我的答案希望它有幫助! – e666

回答

0

您需要使用添加插件:

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

的指示ngcordova文檔上:

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

一定還來調用該插件的任何方法$ionicPlatform.ready後。

編輯 在編譯此插件時出現錯誤,請確保已使用Android SDK管理器安裝Android支持庫。

+0

添加插件導致建立異常(請參閱編輯) –

+0

非常感謝你解決了我的問題 –

相關問題