search

Home  >  Q&A  >  body text

angular.js - ng-model如何绑定二选一的单选项框?

漂亮男人漂亮男人2744 days ago570

reply all(3)I'll reply

  • 阿神

    阿神2017-05-15 17:10:59

    <label>
        <input type="radio" ng-model="sex" value="male">
        <span>男</span>
    </label>
    <label>
        <input type="radio" ng-model="sex" value="female">
        <span>女</span>
    </label>
    {{sex}}

    As for the name attribute, I tried it. As long as the values ​​bound to ng-model are the same, they are considered to be a group

    reply
    0
  • ringa_lee

    ringa_lee2017-05-15 17:10:59

    Use ng-checked

    <label class="">
        <input type="radio" ng-checked="option==1" ng-click="option=1">
        <span>a</span>
    </label>
    <label class="">
        <input type="radio" ng-checked="option==2" ng-click="option=2">
        <span>b</span>
    </label>

    reply
    0
  • 習慣沉默

    習慣沉默2017-05-15 17:10:59

    The radio button box lacks the name attribute. How does the browser know that it is a group of radio button boxes? How does Angular know that it is a group of radio button boxes?

    reply
    0
  • Cancelreply