0
ラジオボタンが3つあり、デフォルトではYESと選択されています。いずれかをボタンなしとして選択すると、送信ボタンが無効になります。 3つのボタンがすべてイエスになると、保存ボタンが有効になります。初めてラジオボタンをクリックしたときにラジオボタンの値が変更されない
私のプロジェクトには以下のコードが書かれています。
app
.controller(
"MainCtrl",
function($scope, $http) {
$scope.formModel = {
internationalClient: 0,
isConfidential: 0,
isModificationLossRecog: 0,
idenComplianceForFinDifficulty: 1,
idenComplianceForConcession: 1,
idenComplianceForModificationOrRefin: 1
};
$(".radioBtn")
.click(
function() {
$("#save").attr("disabled", true);
$scope.forbraranceJson1 = angular.toJson(
$scope.formModel, false);
console.log($scope.forbraranceJson1);
var x1 = JSON.parse($scope.forbraranceJson1);
console.log("11 " + x1.idenComplianceForModificationOrRefin);
console.log("22 " + x1.idenComplianceForFinDifficulty);
console.log("33 " + x1.idenComplianceForFinDifficulty);
if (x1.idenComplianceForModificationOrRefin == 1 && x1.idenComplianceForConcession == 1 && x1.idenComplianceForFinDifficulty == 1) {
$("#save").attr("disabled", false);
$scope.measureCheckbomsg = "";
} else {
//$("#save").attr("disabled", true);
$scope.measureCheckbomsg = "Please select all Forbearance requirements as YES";
}
});
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.6/angular.min.js"></script>
<html ng-app="App">
<body ng-controller="MainCtrl">
<form name="theForm" novalidate="novalidate">
<input type="radio" ng-model="formModel.isModificationLossRecog" ng-value="1">Yes
<input type="radio" ng-model="formModel.isModificationLossRecog" ng-value="0" ng-checked="true">No
<input type="radio" class="radioBtn" ng-model="formModel.idenComplianceForFinDifficulty" ng-value="1" ng-checked="true">Yes
<input type="radio" ng-model="formModel.idenComplianceForFinDifficulty" class="radioBtn" ng-value="0">No
<input type="radio" ng-model="formModel.idenComplianceForConcession" ng-value="1" class="radioBtn" ng-checked="true">Yes
<input type="radio" class="radioBtn" ng-model="formModel.idenComplianceForConcession" ng-value="0">No
<button class="btn btn-success btn-sm" id="save" ng-click="saveRegistration(theForm.$valid)">Save</button>
</body>
</html>
私が初めてに値が0に1を変更しない任意のラジオボタンをクリックしてください。私が2回目をクリックすると、その値はJSONで変化しています。
最初のコントローラ内でそのような
ng-click
またはng-change
ような角度の使用 "NGイベント" で使用している$( '')jqueryの。クリックを避けてください。ラジオでng-changeディレクティブを使用します。 –
ありがとうございました。私は変更を変更しました。今は私のために働いています –