默认情况下,单选按钮不会显示为已选中。我试图默认选中我的第一个选项。但它没有用......任何想法或建议?
<div Class ="form-group">
<label>Select your Email Hierarchy</label>
<div class="radio" ng-switch="deliveryMethod">
<div ng-switch-when="email">
<label>
<input type="radio" id="delivery-email" name="delivery-email"
ng-model="generated.delivery" ng-change="checkValidGenerate()"
class="check" value="EE/ER" checked="checked"/>
EE/ER
</label><br/>
<!-- some code--other option listed -->
答案 0 :(得分:0)
嗯,起初没有必要使用checked
。如果您将value
归因于ngModel
,它应该有效,否则它不会起作用:
$scope.generated.delivery = 'EE/ER';
请参阅以下示例:
(function() {
'use strict';
angular
.module('app', [])
.controller('MainCtrl', MainCtrl);
MainCtrl.$inject = ['$scope'];
function MainCtrl($scope) {
$scope.deliveryMethod = 'email';
$scope.generated = {};
$scope.generated.delivery = 'EE/ER';
}
})();
&#13;
<!doctype html>
<html ng-app="app">
<head>
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.5.7/angular.min.js"></script>
<script src="script.js"></script>
</head>
<body ng-controller="MainCtrl">
<div Class="form-group">
<label>Select your Email Hierarchy</label>
<div class="radio" ng-switch="deliveryMethod">
<div ng-switch-when="email">
<label>
<input type="radio" id="delivery-email" name="delivery-email" ng-model="generated.delivery" ng-change="checkValidGenerate()" value="EE/ER"> EE/ER
</label>
<br/>
</div>
</div>
</div>
</body>
</html>
&#13;