Javascript 调用$scope.$apply()时出现Angularjs错误
调用$digest或apply时出错Javascript 调用$scope.$apply()时出现Angularjs错误,javascript,angularjs,coffeescript,Javascript,Angularjs,Coffeescript,调用$digest或apply时出错 registerAjax = -> successRegister = -> $scope.showRegistrationPanel = false $scope.showEndRegistrationPanel = true $scope.$digest() errorRegister = (response) -> $scope.textErrorPanelRegist
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的:
这将自动等待当前摘要周期完成,然后再调用$apply。是否在代码中使用
jQuery.ajax
。显然,您需要运行摘要周期..或者您可以尝试$timeout(function(){})
要运行安全摘要循环,则无需运行摘要循环。如果您使用$http
方法制作ajax。
$timeout(function() {
$scope.$apply();
});