我正在學習平均值,並且遇到了一個Angular錯誤。我想在一個表格中顯示錶格數據,但是數據是不會通過,我收到的錯誤是:Angular ngRepeat:dupes錯誤(雖然沒有重複的鍵)
angular.js:11500 Error: [ngRepeat:dupes] http://errors.angularjs.org/1.3.5/ngRepeat/dupes?p0=topic%20in%20topics%20%20%7C%20filter%3A%20filter_q&p1=string%3Ap&p2=p at Error (native) at
index.html文件中我有:
discussion_board.controller('dashboardController', function($scope, usersFactory, topicsFactory){
$scope.topics = [];
$scope.users = [];
topicsFactory.index(function(data){
$scope.topics = data;
})
usersFactory.index(function(data){
$scope.topics = data;
})
$scope.addtopic = function(){
console.log("from controller)");
topicsFactory.addTopic($scope.new_topic, function(topics){
$scope.topics = topics;
$scope.new_topic = {};
});
}
})
discussion_board.factory('topicsFactory', function($http){
var factory = {};
var users = [];
factory.index = function(callback) {
$http.get('/topics').success(function(output){
callback();
});
}
factory.addTopic = function(info, callback) {
console.log("from factory");
$http.post('/topics', info).success(function(output){
callback();
});
}
而且在視圖文件中:
<div ng-controller="dashboardController">
<h2>Welcome {{username}} !</h2>
<h5>Search:
<input type="text" ng-model="filter_q" placeholder="search">
</h5>
<table class="table">
<tr>
<th>Category</th>
<th>Topic</th>
<th>User Name</th>
<th>Posts</th>
</tr>
<tr ng-repeat="topic in topics | filter: filter_q">
<td>{{topic.category}}</td>
<td>{{topic.name}}</td>
<td>{{topic.username}}</td>
<td>{{topic.posts}}</td>
</tr>
</table>
我在ng-repeat中添加了$ index的曲目。在過濾器之前添加時,它將一堆空行添加到表中。在過濾器後插入時,沒有變化。
不知道這是有關這個問題,但我想你想改變調用usersFactory.index分配的結果,$範圍.users而不是$ scope.data。 –