AngularJS : Prevent error $digest already in progress when calling $scope.$apply()

前端 未结 28 2698
伪装坚强ぢ
伪装坚强ぢ 2020-11-21 22:31

I\'m finding that I need to update my page to my scope manually more and more since building an application in angular.

The only way I know of to do this is to call

28条回答
  •  说谎
    说谎 (楼主)
    2020-11-21 23:20

    The issue is basically coming when, we are requesting to angular to run the digest cycle even though its in process which is creating issue to angular to understanding. consequence exception in console.
    1. It does not have any sense to call scope.$apply() inside the $timeout function because internally it does the same.
    2. The code goes with vanilla JavaScript function because its native not angular angular defined i.e. setTimeout
    3. To do that you can make use of

    if(!scope.$$phase){
    scope.$evalAsync(function(){

    }); }

提交回复
热议问题