Angular Radio按钮默认激活

时间:2016-03-11 18:59:41

标签: angularjs radio-button checked

为什么默认情况下我的单选按钮无法选中?我做错了什么,我该如何解决?

<label>
    <input type="radio" name="test" ng-model="radioV" value="{'default': 'true', 'foo': 'false'}"/> One 
</label>

$scope.radioV = {
 'default'" : 'true'
}

1 个答案:

答案 0 :(得分:0)

编辑:

基于我提供的示例的概念,试试这个,

<label>
    <input type="radio" name="test" ng-model="radioV.default" value="{'default': 'true', 'foo': 'false'}"/> One 
</label>


$scope.radioV = {
 "default" : 'true'
}

以下是您要实现的目标示例。您可以自己理解并修复代码。

    <script>
  angular.module('radioExample', [])
    .controller('ExampleController', ['$scope', function($scope) {
      $scope.color = {
        name: 'blue'
      };
      $scope.specialValue = {
        "id": "12345",
        "value": "green"
      };
    }]);
</script>
<form name="myForm" ng-controller="ExampleController">
  <label>
    <input type="radio" ng-model="color.name" value="red">
    Red
  </label><br/>
  <label>
    <input type="radio" ng-model="color.name" ng-value="specialValue">
    Green
  </label><br/>
  <label>
    <input type="radio" ng-model="color.name" value="blue">
    Blue
  </label><br/>
  <tt>color = {{color.name | json}}</tt><br/>
 </form>

此示例中,默认情况下选择蓝色。 $ scope.color默认设置它。

https://docs.angularjs.org/api/ng/input/input%5Bradio%5D

中取出示例
相关问题