$申请已在进行中,无需在任何地方使用$ apply

时间:2016-11-05 18:51:21

标签: javascript angularjs

我有以下javascript代码:

$scope.fav_details = function(id1,id2,bio) {
    document.getElementById(id2).style.display="none";
    document.getElementById(id1).style.display="block";
    $scope.getLegislatorDetails(bio);
    document.getElementById(bio).click();
}

引发以下错误的行是上面的点击事件。 我不明白的是,我没有在我的代码中的任何地方应用$ apply我仍然收到此错误。有人能帮我吗。上面代码中的getLegislatorDetails函数有一个api调用,并将数据存储在一个范围变量中。 我有以下角度js错误:

angular.js:13642 Error: [$rootScope:inprog] http://errors.angularjs.org/1.5.6/$rootScope/inprog?p0=%24apply
    at Error (native)
    at https://ajax.googleapis.com/ajax/libs/angularjs/1.5.6/angular.min.js:6:412
    at n (https://ajax.googleapis.com/ajax/libs/angularjs/1.5.6/angular.min.js:137:381)
    at m.$apply (https://ajax.googleapis.com/ajax/libs/angularjs/1.5.6/angular.min.js:145:312)
    at HTMLButtonElement.<anonymous> (https://ajax.googleapis.com/ajax/libs/angularjs/1.5.6/angular.min.js:274:247)
    at HTMLButtonElement.dispatch (http://localhost/congress/js/jquery-3.1.1.min.js:3:10315)
    at HTMLButtonElement.q.handle (http://localhost/congress/js/jquery-3.1.1.min.js:3:8342)
    at m.$scope.fav_details (http://localhost/congress/scripts.js:938:38)
    at fn (eval at compile (https://ajax.googleapis.com/ajax/libs/angularjs/1.5.6/angular.min.js:231:126), <anonymous>:4:436)
    at b (https://ajax.googleapis.com/ajax/libs/angularjs/1.5.6/angular.min.js:126:19)(anonymous function) @ angular.js:13642
angular.js:13642 Error: [$rootScope:inprog] http://errors.angularjs.org/1.5.6/$rootScope/inprog?p0=%24apply
    at Error (native)
    at https://ajax.googleapis.com/ajax/libs/angularjs/1.5.6/angular.min.js:6:412
    at n (https://ajax.googleapis.com/ajax/libs/angularjs/1.5.6/angular.min.js:137:381)
    at m.$digest (https://ajax.googleapis.com/ajax/libs/angularjs/1.5.6/angular.min.js:142:30)
    at m.$apply (https://ajax.googleapis.com/ajax/libs/angularjs/1.5.6/angular.min.js:145:401)
    at HTMLButtonElement.<anonymous> (https://ajax.googleapis.com/ajax/libs/angularjs/1.5.6/angular.min.js:274:247)
    at HTMLButtonElement.dispatch (http://localhost/congress/js/jquery-3.1.1.min.js:3:10315)
    at HTMLButtonElement.q.handle (http://localhost/congress/js/jquery-3.1.1.min.js:3:8342)
    at m.$scope.fav_details (http://localhost/congress/scripts.js:938:38)
    at fn (eval at compile (https://ajax.googleapis.com/ajax/libs/angularjs/1.5.6/angular.min.js:231:126), <anonymous>:4:436)(anonymous function) @ angular.js:13642

可以在以下链接中找到getLegislatorDetails函数: -

https://github.com/anirbanmishra/congress.php/blob/master/getLegislatorDetails

1 个答案:

答案 0 :(得分:0)

如果你附上

ng-click=getLegislatorDetails 

对于生物元素

然后评论以下代码中的任何一行

  $scope.getLegislatorDetails(bio);
        document.getElementById(bio).click();