$scope.identityProof = ["karnataka","Tamilnadu","Andhra","Delhi","Kerala","Bihar"]
<form id="myForm">
<input type="radio" name="myRadio" value="Yes" /> Yes <br />
<input type="radio" name="myRadio" value="No" /> No <br />
</form>
<div ng-app="myApp">
<div ng-controller="AppCtrl">
{{message}} <br />
<!--Options value is defualt 0, 1 ... and it's non change able -->
<span>Default Otions:</span>
<select id="idType" name="idProff" ng-model="completiondetail.IDProofType" ng-options="item.proofName as item.proofName for item in identityProof">
<option value="">--Choose a Document--</option>
</select>
</div>
</div>
我有两个收音机“是”和“否”。下拉值来自服务响应。所以我正在显示这些值。
1)当页面加载时,该时间下拉列表将首次显示“ - 加入文档 - ”。
2)如果我将下拉值选为“是”,我不想做任何事情,它应该有效。
3)如果我将下拉值选为“否”,我想在Dropdown中设置“Delhi”。它应该在Dropown中可见。
答案 0 :(得分:1)
您的单选按钮也应位于<div ng-controller="...">
标记内,以便角度识别值的变化。然后,您可以使用ng-change
来实现您想要的目标。
<select ng-model="selectedVal" ng-options="b for b in identityProof track by b"></select>
<input type="radio" name="radio_select" value="yes" ng-model="selectedRadio"/>Yes
<input type="radio" name="radio_select" value="no" ng-model="selectedRadio" ng-change="selectedVal='Delhi'" />No
这是jsfiddle link。希望这有帮助!
答案 1 :(得分:0)
您正在寻找的简单ng-change
逻辑:
<div ng-controller="MyCtrl">
<input type="radio"
name="myRadio"
ng-model="radioValue"
ng-value="true"
ng-change="validateRadio()" /> Yes<br />
<input type="radio"
name="myRadio"
ng-model="radioValue"
ng-value="false"
ng-change="validateRadio()" /> No<br />
<br />
<select id="idType"
name="idProff"
ng-model="completiondetail.IDProofType"
ng-options="item.proofName as item for item in identityProof track by item">
<option value="" selected>--Choose a Document--</option>
</select>
</div>
var myApp = angular.module('myApp', []);
myApp.controller('MyCtrl', function($scope) {
$scope.radioValue = false;
$scope.identityProof = ["karnataka", "Tamilnadu", "Andhra", "Delhi", "Kerala", "Bihar"];
$scope.completiondetail = {
IDProofType: null
};
$scope.validateRadio = function() {
if ($scope.radioValue) {
$scope.completiondetail.IDProofType = 'Delhi';
}
}
});
<强>&GT; demo fiddle 强>