试图将我的复选框变成单选按钮。这很好用
ng-change="second=false;third = false;fourth = false;"
这是个骗子
http://plnkr.co/edit/yTJUZcFoLsSEBjruRuEY?p=preview
除了 ng-model 之外,有没有办法让数组中的每个元素都为 false?
示例
ng-model=myArray[3]
所以 myArray[0], myArray[1], myArray[... n]
都是 false
EXCEPT myArray[3]
,这是真的。
最佳答案
这应该相当优雅:PLNKR
var app = angular.module('plunker', []);
app.controller('MainCtrl', function($scope) {
$scope.radio = new Array(4).fill(false)
$scope.changed = function(el){
$scope.radio = $scope.radio.map((v,i)=>i==el)
}
});
和 html:
<div>{{radio[0]}}|{{radio[1]}}|{{radio[2]}}|{{radio[3]}}
<br/>
<input ng-repeat="r in radio track by $index" type="checkbox" ng-model="radio[$index]" ng-change="changed($index)" />
关于javascript - 有没有更优雅的方法将复选框变成单选按钮?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44278629/