简体   繁体   English

在ng-repeat中单击显示/隐藏按钮

[英]Show/Hide button onclick in ng-repeat

Hy guys, I'm having troubles showing and removing button in ng-repeat. 大家好,我在显示和删除ng-repeat中的按钮时遇到了麻烦。

<div class="row" ng-repeat="a in b">
   <button type="button" ng-click="add()">+</button>
   <button type="button" ng-click="remove()">-</button>
</div>

it's repeating b times, I want to be visible only add button and on click i want to hide add button and show remove button, but only in that exact iteration. 它重复了b次,我只想看到添加按钮,单击后我就想隐藏添加按钮并显示删除按钮,但只在那个确切的迭代中。 I don't want other repeats to be affected. 我不希望其他重复项受到影响。 Also for remove button on click I want to hide it and show add button again. 同样对于单击删除按钮,我想将其隐藏并再次显示添加按钮。

I could do it inside controller or inline. 我可以在控制器或内联中执行此操作。

Thanks in advance! 提前致谢!

You should have some property in a like "added" or "remove" then you can check is added is true or if remove is true 您应该在“ added”或“ remove”之类的属性中添加一些属性,然后才能检查添加的内容是否为true或remove是否为true

<div class="row" ng-repeat="a in b">
   <button type="button" ng-if="!a.added" ng-click="add(a)">+</button>
   <button type="button" ng-if="a.added" ng-click="remove()">-</button>
</div>

You on click method would be 您点击方法将是

function add(x) {
 ... code here
 x.added = true
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM