我用ng-repeat生成了一個列表,其中每個項目都有一個計數變量。在每個列表項目中,我都有一個鏈接。單擊ng-repeat中的項目時,如何增加計數器?
我想單擊鏈接時增加計數。
我試過以下的方法,但它不工作。
我的控制器: -
myApp.controller('allpost', function ($scope, $http, $stateParams, Allposts) {
var id = $stateParams.id;
Allposts.GetAllposts(id).then(
function (response) {
$scope.allPosts = response.data.posts;
});
function ctrl($scope) {
$scope.increment = function(item){
item.count += 1;
}
}
})
和查看,如: -
<ion-content class="padding" lazy-scroll>
<div class="row no-padding HomeRowsList">
<div class="item itemfull" ng-repeat="post in allPosts">
<div class="item item-body">
<div>
<div class="title-news">
<div class="title" ng-bind-html="post.content"></div>
<div class="countbg">عدد المرات : {{post.custom_fields.azkarno}}</div>
<span>{{post.count}}</span><a onclick="ctrl(post);">Increment</a>
</div>
</div>
</div>
</div>
</div>
</ion-content>
您還沒有生成*列表*,你生成了一堆unsemantic,嵌套的'div's的。 – connexo