【发布时间】:2016-11-05 03:51:18
【问题描述】:
我的控制器:
.controller('BlogController', function(blogFactory, $routeParams, $scope){
var that=this;
stat=false;
this.checkbookmark = function(bId){
console.log(bId)
blogFactory.checkBookmark(bId, function(response){
console.log(response)
if(response == "bookmarked"){
that.stat = true;
}
else{
that.stat = false;
}
})
}
我的html代码:
<div class="container" ng-controller="BlogController as blogCtrl">
<div class="row" ng-repeat="chunk in blogCtrl.blogs | filter: filter_name | orderBy:'-created_at' | groupBy: 3">
<div class="outerbox1 col-sm-4" ng-repeat="blog in chunk" >
<div class="innerbox3" ng-init="blogCtrl.checkbookmark(blog._id)">
<br>
<div> > READ MORE
<a ng-if="blogCtrl.stat" ng-href="#" ng-click="blogCtrl.removebookmark(blog._id)" class="glyphicon glyphicon-heart pull-right">{{blogCtrl.stat}}</a>
<a ng-if="!blogCtrl.stat" ng-href="#" ng-click="blogCtrl.addbookmark(blog._id)" class="glyphicon glyphicon-heart-empty pull-right">{{blogCtrl.stat}}</a>
</div>
</div>
</div>
</div>
</div>
服务工厂:
factory.checkBookmark = function(info, callback){
$http({
url:'api/check_bookmark_blog',
method:'POST',
headers:{'x-access-token': token},
params:{'user_id': userid},
data:{'blog_id':info}
}).success(function(data){
console.log(data);
callback(data)
})
}
我想根据 stat 的值显示 glyphicon
我有 6 个博客,前 3 个有书签,后 3 个没有。
我遇到的问题是 stat 值始终根据最后一个书签设置,因此它始终为 false / true(基于上一个博客的条件)。
如何解决此问题并将 glyphicon 分别设置为每个博客的 stat 值?
【问题讨论】:
-
尝试在你的 innerbox3 元素中使用 ng-class
-
@SahilChauhan 它不起作用......它进入无限循环。
-
hmm.. 你能给我更多你的服务设置的代码吗?
-
@SahilChauhan 请检查更新后的问题
标签: html angularjs node.js express