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

前端 未结 28 2787
伪装坚强ぢ
伪装坚强ぢ 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:01

    You can use

    $timeout

    to prevent the error.

     $timeout(function () {
                            var scope = angular.element($("#myController")).scope();
                            scope.myMethod();
                            scope.$scope();
                        },1);
    

提交回复
热议问题