【发布时间】:2014-09-01 13:04:48
【问题描述】:
我通过从 http 服务加载它们来初始化 angular.js 中的对象数组。
<ul class="order-list" ng-repeat="catalog in catalogs">
<li style="width:34%;" ng-show="{{catalog.ordered}}" ><span class="fa fa-money"></span> ORDERED </li>
</ul>
$scope.catalogs = [];
$http({
url: baseURL + "/orders/"+order.date + "?code="+order.code,
method: "DELETE",
}).success(function (data, status, headers, config) {
$scope.catalogs = data;
// first way
_.each($scope.catalogs, function( catalog){
console.log(catalog);
catalog.ordered = true;
})
// second way
setTimeout( function(){
console.log("settimeout");
_.each($scope.catalogs, function( catalog){
console.log(catalog);
catalog.ordered = true;
})
$scope.$apply();
}, 2000)
})
和代码一样,如果我使用第一种方式,那么 html 会立即显示更新,但是,如果我使用第二种方式,延迟三秒后更新,那么 html 不会显示任何更新,甚至我用 $scope.$apply();它只是给了我一个错误 错误:[$rootScope:inprog] http://errors.angularjs.org/1.3.0-beta.17/$rootScope/inprog?p0=%24digest
如何进行更新
【问题讨论】:
标签: angularjs