我是 AngularJS 的新手,我正在用 Angular 制作博客,但是在我有文章列表的部分,Chrome 控制台给我这个错误,并且列表丢失。我在 PHP 中有后端,与数据库的连接似乎没问题,因为当我写一篇新文章时,数据进入数据库,但数据似乎不会返回前端。我尝试用谷歌搜索,但找不到任何有用的信息来解决这个问题。谢谢您的建议!
http://errors.angularjs.org/1.4.1/ngRepeat/dupes?p0=blog%20in%20blogs&p1=string%3A%3C&p2=%3C
这是博客前端:
<table class="table table-striped">
<tr>
<th>Title</th><th>Description</th><th>Added</th><th>Remove</th>
</tr>
<tr ng-repeat="blog in blogs">
<td>{{ blog.title }}</td><td>{{ blog.description }}</td><td>{{ blog.added_date }}</td><td><button class="btn btn-danger" ng-click="removeData(blog.id)">x</button></td>
</tr>
</table>
这是 Angular :
$scope.frmToggle = function() {
$('#blogForm').slideToggle();
}
$http.get('./js/popData.php')
.success(function(data) {
$scope.blogs = data;
})
.error(function(err) {
$log.error(err);
})
$scope.pushData = function($params) {
$http.post('./js/pushData.php',{'title':$params.title, 'description':$params.description})
.success(function(data) {
$scope.blogs = data;
})
.error(function(err) {
$log.error(err);
})
}
$scope.removeData = function($params) {
var cnfrm = confirm("Are you sure to delete?");
if(cnfrm) {
$http.post('./js/removeData.php', {'id':$params})
.success(function(data) {
$scope.blogs = data;
})
.error(function(err) {
$log.error(err);
})
} else {
//
}
}
最佳答案
像这样使用:
<tr ng-repeat="blog in blogs track by $index">
<td>{{ blog.title }}</td><td>{{ blog.description }}</td><td>{{ blog.added_date }}</td><td><button class="btn btn-danger" ng-click="removeData(blog.id)">x</button></td>
</tr>
有关受骗者的详细信息 check AngularJs documentation
希望这对您有帮助。
关于javascript - http ://errors. angularjs.org/1.4.1/ngRepeat/dupes,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37045430/