【发布时间】:2016-05-17 04:29:57
【问题描述】:
我正在学习 MEAN,但遇到了 Angular 错误。我正在尝试在表格中显示表单数据,但是数据没有通过,我收到的错误是:
angular.js:11500 错误:[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 在错误(本机) 在
在我的 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 的调用以将结果分配给 $scope.users 而不是 $scope.data。
标签: javascript angularjs