我有两个单选按钮,我需要根据检查来切换它们的值 例如,检查时将a的值转换为TRUE,将B的值设置为FALSE,反之亦然
<ion-radio ng-model="form.Domistric" value="1" ng-value="!form.International">Domestic</ion-radio><br />
<ion-radio ng-model="form.International" value="0" ng-value="!form.Domistric">International</ion-radio>
有没有一个动态的角色来做那个?
答案 0 :(得分:2)
您可以使用ng-true-value和ng-false-value
<ion-radio ng-model="form.Domistric" ng-true-value="!form.International" ng-false-value="form.International">Domestic</ion-radio><br />
<ion-radio ng-model="form.International" ng-true-value="!form.Domistric" ng-false-value="form.Domistric">International</ion-radio>
答案 1 :(得分:0)
尝试以下代码解决您的问题,只需将<input>
替换为<ion-checkbox> </ion-checkbox>
var app = angular.module('myApp', []);
app.controller('MainCtrl', function ($scope) {
$scope.form = {};
$scope.changeD = function () {
$scope.form.International = false;
}
$scope.changeI = function () {
$scope.form.Domistric = false;
}
});
<!DOCTYPE html>
<html ng-app="myApp">
<head>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
</head>
<body ng-controller="MainCtrl">
<input type="checkbox" ng-model="form.Domistric" ng-change="changeD()" />Domestic
<input type="checkbox" ng-model="form.International" ng-change="changeI()" />International
</body>
<p>Domestic: {{form.Domistric}}</p>
<p>International: {{form.International}}</p>
</html>