search

Home  >  Q&A  >  body text

angular.js - angular gets the value of the radio option, waiting online, dear, I have been working overtime for a week...

The radio selection options are generated by ng-repeat,

<label class="radio-inline" ng-repeat="list in fruits">
   <input type="radio" name="sample" value="{{list.fruitName}}"> {{list.fruitName}}
</label>

// list对象格式
list = {
    fruitName: '苹果',
    id: 001
};

Now I want to 获取被选中的那个选项的id. For example, if I choose Apple, Apple’s ID 001 will be returned at this time. How to achieve this?

I’m really waiting online. I’m so anxious. I’ve been working overtime for a week...Jianhu is asking for help. Thank you very much!

迷茫迷茫2843 days ago791

reply all(2)I'll reply

  • 巴扎黑

    巴扎黑2017-05-15 17:09:52

    <label class="radio-inline" ng-repeat="list in fruits">
       <input type="radio" name="sample" ng-value="list.id" ng-model="id"> {{list.fruitName}}
    </label>
    

    You can get it by using $scope.id in the controller

    reply
    0
  • 曾经蜡笔没有小新

    曾经蜡笔没有小新2017-05-15 17:09:52

    ng-model

    reply
    0
  • Cancelreply