单选按钮的价值,模型和点击

Radio Buttons ng-value, ng-model and ng-click

我有一个简单的表单,可以呈现项目并提供单选按钮。单选按钮按预期呈现。我的目标是在 selectRadioButton 函数中获取 'item.chosen' 值。我收到了商品,但 item.chosen 未定义。我在这里做错了什么?
HTML:

<div class="item" ng-if="ctrl.items" ng-repeat="item in ctrl.items">
    <input type="radio" ng-model="item.chosen"
        ng-value=true ng-click="ctrl.selectRadioButton(item)">
</div>

记者:
this.selectRadioButton = function(item){
    if(item.chosen) {
        console.log('Got the chosen value');
    }
}

这里有一些示例代码,说明您应该如何在 AnuglarJS 上使用单选按钮。

控制器:

  angular.module('radioExample', [])
    .controller('ExampleController', ['$scope', function($scope) {
      $scope.color = {
        name: 'blue'
      };
      $scope.specialValue = {
        "id": "12345",
        "value": "green"
      };
    }]);

HTML:

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

查看documentation了解更多信息