【问题标题】:Angular Radio button default activeAngular 单选按钮默认激活
【发布时间】:2016-06-27 03:39:04
【问题描述】:

为什么我不能默认选择我的单选按钮?我做错了什么,我该如何解决?

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

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

【问题讨论】:

    标签: angularjs radio-button checked


    【解决方案1】:

    编辑:

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

    <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为例

    【讨论】:

    猜你喜欢
    • 2017-10-02
    • 2018-04-21
    • 2019-08-19
    • 2014-01-07
    • 1970-01-01
    • 1970-01-01
    • 2020-12-04
    • 2014-12-12
    • 2018-12-26
    相关资源
    最近更新 更多