admin管理员组文章数量:1415111
I built buttons with ng-repeat:
<button ng-repeat="alphabet in alpha" ng-click="checkAlpha()" value="{{alphabet}}">{{alphabet}}</button>
$scope.alpha = 'abcdefghijklmnopqrstuvwxyz';
The question is how to remove only the button that is clicked. I used ng-hide in button, but then all the buttons are gone. What is the best way to do that? Thanks
I built buttons with ng-repeat:
<button ng-repeat="alphabet in alpha" ng-click="checkAlpha()" value="{{alphabet}}">{{alphabet}}</button>
$scope.alpha = 'abcdefghijklmnopqrstuvwxyz';
The question is how to remove only the button that is clicked. I used ng-hide in button, but then all the buttons are gone. What is the best way to do that? Thanks
Share Improve this question edited Dec 18, 2013 at 12:29 ishwr asked Dec 18, 2013 at 10:50 ishwrishwr 7453 gold badges14 silver badges37 bronze badges 3- ng-click="checkAlpha($index)" and provide implementation in checkAlpha() method to handle the deletion by index :) – Holybreath Commented Dec 18, 2013 at 10:55
- 2 You can use $index. There is a jsfiddle here jsfiddle/SX4gE/11 – Mehmet Commented Dec 18, 2013 at 10:56
- Good fiddle, I've updated it to match the question :) Upvoted. – Holybreath Commented Dec 18, 2013 at 11:13
1 Answer
Reset to default 3HTML:
<div ng-controller='ctrl'>
<button ng-repeat='alphabet in alpha ' ng-click="checkAlpha($index)" value="{{alphabet}}" id="{{$index}}">{{alphabet}}</button>
</div>
JS:(similar)
angular.module("app", []).controller("ctrl", function ($scope) {
//lets create array from a string.
$scope.alpha = 'abcdefghijklmnopqrstuvwxyz'.split("");
$scope.checkAlpha = function(index) {
$scope.alpha.splice(index, 1);//remove
}
});
FIDDLE:
http://jsfiddle/SX4gE/20/
本文标签: javascriptAngular js Remove certain element from ngrepeatStack Overflow
版权声明:本文标题:javascript - Angular js: Remove certain element from ng-repeat - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745210024a2647827.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论