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
Add a ment  | 

1 Answer 1

Reset to default 3

HTML:

 <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