你好我在ng-repeat中有一个div,我初始化了两个ng-init变量,以便能够确定是否发生了点击事件。我面临的问题是每当我点击一个like或reblog按钮时,我的ng-repeat中的每个其他帖子都会反映出这种变化
<div class="col-sm-4" ng-repeat="post in postfeed">
<ul>
<li ng-init="reblog = false">
<button class="btn glyphicon glyphicon-link" ng-click="reblogged(post.key,reblog); reblog = !reblog" ng-class="{clicked:reblog}"></button>
</li>
<li ng-init="like = false">
<button class="btn glyphicon glyphicon-heart" ng-click="liked(post.key,like); like= !like" ng-class="{clicked:like}"></button>
</li>
</ul>
</div>
我的功能只是接受了值,但没有对项目进行任何更改,但我的布尔值没有被更改
答案 0 :(得分:0)
简单的解决方案 -
<div class="col-sm-4" ng-repeat="post in postfeed">
<ul>
<li ng-init="post.reblog = false">
<button class="btn glyphicon glyphicon-link" ng-click="reblogged(post.key,post.reblog); post.reblog = !post.reblog" ng-class="{clicked:post.reblog}"></button>
</li>
<li ng-init="post.like = false">
<button class="btn glyphicon glyphicon-heart" ng-click="liked(post.key,post.like); post.like= !post.like" ng-class="{clicked:post.like}"></button>
</li>
</ul>