【问题标题】:$rootScope:infdig 10 $digest() iterations reached in angularJS$rootScope:infdig 10 $digest() 迭代在 angularJS 中达到
【发布时间】:2014-10-11 03:50:44
【问题描述】:

我正在实施传单角度指令。在 $scope.marker 中推送标记时出现以下错误。

[$rootScope:infdig] 达到 10 次 $digest() 迭代。中止! 在最后 5 次迭代中触发的观察者:

如何消除此错误

  var shorLocationUrl = _baseUrl + "userService/" + "111234567" +"/fetchUserLatLng?userId="+$stateParams.contactId+"&lastNLatLng=5";
     var  responsePromise = $http.get(shorLocationUrl,{ cache: false });

            responsePromise.success(function(data, status, headers, config) {
              console.log(JSON.stringify(data));

                  var latLonglist = data.geolocationList;
                 // console.log(latLonglist[0]);
                  $scope.markers = new Array();
                  for (var i = 0; i < latLonglist.length; i++) {
                    // console.log( geolocationList[i]);
                     //var latLong = latLonglist[i].split(","); 
                     console.log(latLonglist[i].latitude);
                     console.log(latLonglist[i].logitude);

                           $scope.markers.push({

                                lat:Number(latLonglist[i].latitude) ,
                                lng:Number(latLonglist[i].logitude) ,
                                icon: {
                                    iconUrl: 'img/whami.png',
                                    iconSize: [35, 35],
                                    iconAnchor: [40, 80],
                                    popupAnchor: [0, 0],
                                    shadowSize: [0, 0],
                                    shadowAnchor: [0, 0]
                                },
                                focus: true,
                                message:latLonglist[i].tickitSubject,
                                label: {
                                message: "Hey",
                                options: {
                                    noHide: true
                                    }
                               }
                           });


                  };

    //console.log(JSON.stringify($scope.markers));

           })

           responsePromise.error(function(data, status, headers, config) {
            console.log(JSON.stringify(data)); 

           })

【问题讨论】:

    标签: angularjs leaflet ionic-framework


    【解决方案1】:

    这意味着 angular 检测到可能存在无限循环。虽然可以配置 10 次迭代限制;确保您没有同时观看和更换模型。

    因为当调用 $digest() 时,所有被监视的监听器都会被执行;并将根据需要循环,直到被监视的表达式不再发生变化。

    【讨论】:

      最近更新 更多