javascript - Angular js: Remove certain element from ng-repeat - Stack Overflow

I built buttons with ng-repeat:<button ng-repeat="alphabet in alpha" ng-click="checkA

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/

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745210024a4616781.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信