致电$ digest或申请时发生错误
registerAjax = ->
successRegister = ->
$scope.showRegistrationPanel = false
$scope.showEndRegistrationPanel = true
$scope.$digest()
errorRegister = (response) ->
$scope.textErrorPanelRegistration = response.data.error
$scope.showErrorPanel = true
$scope.$apply()
data =
password: $scope.user.password
firstName: $scope.user.firstName
lastName: $scope.user.lastName
email: $scope.user.email
http.post REGISTER_URL, data
.then successRegister, errorRegister
当调用$ digest或$ apply时,错误消失了,但是一切正常
Error: [$rootScope:inprog] http://errors.angularjs.org/1.4.7/$rootScope/inprog?p0=%24digest
at Error (native)
at http://localhost:8000/lib/angular/angular.min.js?M420gm3LwzcQLAcaXrk6IQ:6:416
最佳答案
使用Angular的$timeout service:
$timeout(function() {
$scope.$apply();
});
在调用$ apply之前,这将自动等待当前摘要周期完成。