我按照此 guide 在 Angular 和 Rails 中构建了 Reddit 克隆。我一直在尝试使用 CSS 来将赞成票和反对票箭头放在正确的位置。我想覆盖 Bootstrap 不是一个好主意,因为当我单击箭头时,我似乎无法让 ng-click 触发(以前工作正常,根本没有改变 js)。以下是相关部分:
HTML:
<div class="row">
<div class="col-md-1 small-right-gutters small-col">
<div class="row">
<div class="col-md-1 small-right-gutters">
<div class="glyphicon glyphicon-arrow-up" ng-click="addUpvote(post)"></div>
<div class="glyphicon glyphicon-arrow-down"></div>
</div>
<div class="col-md-1 vert-center">
{{post.upvotes}}
</div>
</div>
</div>
<div class="col-md-9 big-col vert-center">
<a ng-show="post.link" href="{{post.link}}">
{{post.title}}
</a>
<span ng-hide="post.link">
{{post.title}}
</span>
</div>
<div class="col-md-2 text-right">
<div>
<small><a href="#/posts/{{post.id}}">{{ post.comments.length }} comment<span ng-hide="post.comments.length==1">s</span></a></small>
</div>
<div>
<small>posted by <a ng-href="#/users/{{post.user.username}}">{{post.user.username}}</a></small>
</div>
</div>
</div>
CSS:
.small-right-gutters {
padding-right: 2px;
}
.small-col {
width: 40px;
}
.big-col {
width: 925px;
font-size:20px;
margin-left: 10px;
}
.vert-center {
height: 40px;
line-height: 40px;
}
Angular Controller :
$scope.addUpvote = function (post) {
postFactory.upvotePost(post);
};
$scope.addDownvote = function (post) {
postFactory.downvotePost(post);
};
Angular 工厂:
upvotePost: function(post) {
return $http.put('/posts/' + post.id + '/upvote.json').success(function (data) {
post.upvotes += 1;
});
},
downvotePost: function(post) {
return $http.put('/posts/' + post.id + '/downvote.json').success(function (data) {
post.upvotes -= 1;
});
},
有什么想法为什么会发生这种情况吗?
最佳答案
如果您在 .glyphicon
上添加 z-index: 1;
,它就可以工作!
关于javascript - 无法点击我的 Angular-rails Reddit 克隆上的赞成票,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33713706/