我用ng-repeat构建按钮:
<button ng-repeat="alphabet in alpha" ng-click="checkAlpha()" value="{{alphabet}}">{{alphabet}}</button>
$scope.alpha = 'abcdefghijklmnopqrstuvwxyz';
问题是如何仅删除单击的按钮。我在按钮中使用了ng-hide,但随后所有按钮都消失了。 最好的方法是什么? 感谢
答案 0 :(得分:3)
HTML:
<div ng-controller='ctrl'>
<button ng-repeat='alphabet in alpha ' ng-click="checkAlpha($index)" value="{{alphabet}}" id="{{$index}}">{{alphabet}}</button>
</div>
JS:(相似)的
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: