Javascript AngularJS ng repeat在Ajax调用后不更新
我有一个AngularJS应用程序。 在应用程序的右侧,我与客户保持聊天 html如下所示:Javascript AngularJS ng repeat在Ajax调用后不更新,javascript,angularjs,ajax,dom,data-binding,Javascript,Angularjs,Ajax,Dom,Data Binding,我有一个AngularJS应用程序。 在应用程序的右侧,我与客户保持聊天 html如下所示: <div class="recent" ng-show="show_chat_list"> <h2></h2> <div ng-repeat="customer in recent_customer_list track by $index" ng-click="start_chat(recent_client_id[$index])" clas
<div class="recent" ng-show="show_chat_list">
<h2></h2>
<div ng-repeat="customer in recent_customer_list track by $index" ng-click="start_chat(recent_client_id[$index])" class='user'>
<a href="#" ng-class="{'red-background': notify[$index]}">
<img ng-src="">
<div class="user-data">
<span class='name'> {{ notify }} </span>
<span class='name'>{{ customer.name }}</span>
</div>
</a>
</div>
</div>
在控制器中:
pollData();
function pollData(){
Poller.poll().then(function(res){
$scope.recent_customers_list = res.customers;
console.log($scope.recent_customers_list[0].name);
$scope.recent_client_id = res.clients_id;
$scope.notify = res.notify;
$timeout(pollData, 1000);
});
}
console.log函数始终打印正确的名称(即使我更改了名称),但在html中并不反映客户端列表的动态更改(例如,如果我更改名称或添加客户端)
如果我插入
$scope.$apply();
或
就在$timeout行之前,我得到一个错误:
Error: [$rootScope:inprog] $digest already in progress
如果在functino pollData()行之后和Poller.poll()行之前插入apply,则会出现以下错误:
Error: [$rootScope:inprog] $apply already in progress
但我的名单根本没有更新。我需要刷新以查看更改。
如何解决此问题?在控制器中,您正在使用
$scope.recent_customers_list
recent_customer_list
但在html中,您使用的是
$scope.recent_customers_list
recent_customer_list
我相信这是一个简单的打字错误 在控制器中,您正在使用
$scope.recent_customers_list
recent_customer_list
但在html中,您使用的是
$scope.recent_customers_list
recent_customer_list
我相信这是一个简单的打字错误 我爱你。我绝望了:)我爱你。我绝望了:)