Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 调用$scope.$apply()时出现Angularjs错误_Javascript_Angularjs_Coffeescript - Fatal编程技术网

Javascript 调用$scope.$apply()时出现Angularjs错误

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

调用$digest或apply时出错

  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();
});