PhoneGap插件navigator.notification.alert AngularJS中的错误

时间:2015-12-16 04:59:59

标签: angularjs cordova phonegap-plugins

如果我在控制器中使用navigator.notification.alert方法,它的工作原理如下:

angular.module('app.login')
  .controller('LoginController',LoginController);

LoginController.$inject = [...];

function LoginController(...){
  ...
  navigator.notification.alert(
      'Username or Password incorrect. Please try again.',// message
      null,             // callback
      'Freedom Nation', // title
      'Ok'              // buttonName
  );
  ...
}

但如果我在工厂使用它,我会得到$digest already in progress error。工厂:

angular
    .module('blocks.logger')
    .factory('logger', logger);

logger.$inject = ['$log'];

function logger($log) {
...
navigator.notification.alert(
    'Username or Password incorrect. Please try again.',// message
    null,             // callback
    'Freedom Nation', // title
    'Ok'              // buttonName
);
...
}

为什么我在factory但未在controller中收到此错误?

错误讯息:

Uncaught TypeError: Cannot read property 'alert' of undefined
Uncaught Error: [$rootScope:inprog] $digest already in progress
Error: [$rootScope:inprog] $digest already in progress

0 个答案:

没有答案