search

Home  >  Q&A  >  body text

angular.js - How to select radio by default in angularjs

<label class="radio-inline">
<input name="display" type="radio" value="true" ng-model="institution.display" checked required>显示
</label>
<label class="radio-inline">
<input name="display" type="radio" value="false" ng-model="institution.display">隐藏</label>

How to select the first one by default in angularjs

PHP中文网PHP中文网2840 days ago1397

reply all(6)I'll reply

  • 为情所困

    为情所困2017-05-15 16:57:10

    Just use ng-checked.

    <label class="radio-inline">
      <input name="display" type="radio" value="true" ng-model="institution.display" ng-checked="true" required>
        显示
    </label>
    <label class="radio-inline">
      <input name="display" type="radio" value="false" ng-model="institution.display">
      隐藏
    </label>

    reply
    0
  • 仅有的幸福

    仅有的幸福2017-05-15 16:57:10

    Set the value of

    institution.display to the corresponding

    reply
    0
  • 某草草

    某草草2017-05-15 16:57:10

    checked = "checked"

    reply
    0
  • 过去多啦不再A梦

    过去多啦不再A梦2017-05-15 16:57:10

    ng-checked  

    Just add the ng-model binding element at the same time

    reply
    0
  • 某草草

    某草草2017-05-15 16:57:10

    Two-way binding
    Two-way binding
    Two-way binding
    It’s important to say it three times~~~

    $scope.institution.display = "true";

    That is, ng-model and value can be the same.

    reply
    0
  • 淡淡烟草味

    淡淡烟草味2017-05-15 16:57:10

    can be found in ng-repeat 中使用 ng-checked , in the form:

    <label ng-repeat="(key, val) in genders track by $index">
        <input type="radio" name="gender" value="{{key}}" ng-checked="list.gender==key">{{val}}
    </label>

    reply
    0
  • Cancelreply