我正在使用ng值爲對象設置無線電輸入值,因此當值與ng模型對象匹配時,它應該導致無線電被檢查。這裏有一個例子和plunker。使用ng值加載時取消選中角度無線電輸入
<script>
angular.module('test', [])
.controller('testController', ['$scope', function($scope) {
$scope.Obj = {
"id": "1",
"value": "green"
};
$scope.ObjTwo = {
"id": "2",
"value": "red"
};
$scope.ObjThree = {
"id": "3",
"value": "blue"
};
$scope.modelObj = {
"id": "3",
"value": "blue"
};
}]);
</script>
<form name="myForm" ng-controller="testController">
<label>
<input type="radio" ng-model="modelObj" ng-value="Obj">
{{Obj}}
</label><br/>
<label>
<input type="radio" ng-model="modelObj" ng-value="ObjTwo">
{{ObjTwo}}
</label><br/>
<label>
<input type="radio" ng-model="modelObj" ng-value="ObjThree">
{{ObjThree}}
</label><br/>
color = {{modelObj}}<br/>
https://plnkr.co/edit/aAISUTEqdGkpVrEJt0uq?p=preview
看來點擊單選按鈕,當作爲modelObj更新到相關目標做工精細。但爲什麼不是在加載時檢查第三個無線電輸入(objThree)?我想,因爲$ scope.Objthree等於$ scope.modeObj在控制器中設置,它將檢查無線電輸入?