如果我在控制器中使用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