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/
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745210024a4616781.html
评论列表(0条)