[英]ng-change event called for radio buttons that are created using ng-repeat the first time but not for second time
如何從單選按鈕事件的onchange調用updateRow方法
當單選按鈕更改時,我需要每次都調用updateRow方法,但當前僅是第一次調用它。
HTML:
<div ng-repeat="b in RS_BehaviorActions">
<input id="{{b.name}}" type="radio" name="behavior" value="{{b.name}}" style="padding:10px;" ng-model="selBehaviorVal" ng-change="updateRow(obj, selBehaviorVal)" /><label>{{b.name}}</label>
</div>
js:
//on change of updateRow method need to push radio button value into json
$scope.updateRow = function ( obj, selectedItem) {
$scope.selectedItem = selectedItem;
$scope.existInArray = false;
for (var i = 0; i < $scope.permissionArray.length; i++) {
if ($scope.permissionArray[i].relationShip == $scope.relationShip) {
$scope.existInArray = true;
break;
}
}
if ($scope.existInArray) {
for (var i = 0; i < $scope.permissionArray.length; i++) {
if ($scope.permissionArray[i].relationShip == $scope.relationShip) {
index = i;
break;
}
}
//$scope.permissionArray.splice(index, 1);
$scope.permissionArray[index].behavior = $scope.selectedItem;
}
else {
$scope.permissionArray.push({ "relationShip": $scope.relationShip, "behavior": $scope.selectedItem });
}
console.log($scope.permissionArray);
}
您可以嘗試使用ng-click
而不是ng-change
。 如果您發布jsFiddle,則為您提供適當的解決方案將更加容易。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.