我有ng-repeat
一个div
包含一个按钮的。假设 div 使用 5 个按钮重复 5 次。我想在单击第二个按钮时禁用它。如何禁用该索引处的按钮?
<div ng-repeat='thing in things'>
<button ng-click='clickToDisable($index)'>button</button>
</div>
像这样的东西。我试过ng-disabled= 'disableButton == $index
了,但这只会禁用所有按钮。
我有ng-repeat
一个div
包含一个按钮的。假设 div 使用 5 个按钮重复 5 次。我想在单击第二个按钮时禁用它。如何禁用该索引处的按钮?
<div ng-repeat='thing in things'>
<button ng-click='clickToDisable($index)'>button</button>
</div>
像这样的东西。我试过ng-disabled= 'disableButton == $index
了,但这只会禁用所有按钮。
你可以传入$event
click 函数并将 disabled 属性设置为 true,如下所示:
<div ng-repeat='thing in things'>
<button ng-click='clickToDisable($event)'>button</button>
</div>
在控制器中:
$scope.clickToDisable = function(evt) {
evt.currentTarget.setAttribute('disabled', 'true');
}
这是它的工作原理。