我用ng-repeat生成了一个列表,其中每个项目都有一个count变量。在每个列表项中,我都有一个链接。
单击链接时,我想增加计数。
我尝试了以下方式,但是没有用。
我的控制器:
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>
在控制器中使用
$scope.increment = function(item){
item.count += 1;
};
代替
function ctrl($scope) {
$scope.increment = function(item){
item.count += 1;
}
}
并在html中使用
<span>{{post.count}}</span><a data-ng-click="increment(post)">Increment</a>
代替
<span>{{post.count}}</span><a onclick="ctrl(post);">Increment</a>
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句