我有四个按钮:
<button ng-disabled = "isDisabled1" ng-click="someFunc('isDisabled1')"></button>
<button ng-disabled = "isDisabled2" ng-click="someFunc('isDisabled2')"></button>
<button ng-disabled = "isDisabled3" ng-click="someFunc('isDisabled3')"></button>
<button ng-disabled = "isDisabled4" ng-click="someFunc('isDisabled4')"></button>
现在当click event fires
对任何一个按钮calls the someFunc()
function
进行disable the button that was clicked.
时我想要controller
我在$scope.someFunc(toDisable){
$scope.toDisable = true;
}
:
{{1}}
但这不起作用。任何想法如何。我是AngularJS的新手。
答案 0 :(得分:0)
使用地图存储值
例如:$scope.isDisabled={
isDisabled1:false,
isDisabled2:false,
.
.
.
}
并在
$scope.someFunc(toDisable){
$scope.isDisabled[toDisable]= true;
}
答案 1 :(得分:0)
另一种简单的方法是使用ng-click
指令来计算将操纵ng-disabled
指令中使用的变量的表达式。
e.g。
<button ng-disabled="ds1" ng-click="ds1 = true">btn1</button>
<button ng-disabled="ds2" ng-click="ds2 = true">btn2</button>
<button ng-disabled="ds3" ng-click="ds3 = true">btn3</button>
<button ng-disabled="ds4" ng-click="ds4 = true">btn4</button>
相关的plunker here。