调用$ scope中的Angularjs错误。$ apply()

时间:2015-12-13 14:54:04

标签: javascript angularjs coffeescript

调用$ 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

1 个答案:

答案 0 :(得分:1)

使用Angular的$timeout service

$timeout(function() {
  $scope.$apply();
});

这将在调用$ apply之前自动等待当前摘要周期完成。