gpt4 book ai didi

javascript - Angularjs 调用 $scope.$apply() 时出错

转载 作者:行者123 更新时间:2023-11-27 23:34:24 25 4
gpt4 key购买 nike

调用 $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 的 $timeout service :

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

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

关于javascript - Angularjs 调用 $scope.$apply() 时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34252391/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com