使用ng-repeat的角度单选按钮

时间:2013-08-06 13:56:46

标签: angularjs radio-button ng-repeat

我在这里做错了什么? js小提琴:http://jsfiddle.net/A2qCS/4/

<div data-ng-controller="PostsController">
    <label data-ng-repeat="option in options" >
        <input type="radio" data-ng-modal= "options.text" data-ng-value="{{option.text}}" />{{option.text}}
        <br/>         
    </label>
</div>

控制器:

var demoApp = angular.module('demoApp', []);
demoApp.controller('PostsController', function($scope, $http) {

    $scope.options = [{ text: '1 Year Americas Best Support for Students' },
        { text: '2 Year Americas Best Support for Students' },
        { text: '3 Year Americas Best Support for Students' }
    ];
    $scope.defaultOption = '1 Year Americas Best Support for Students';
    $scope.newValue = function(value) {
        console.log(value);
    };
});

1 个答案:

答案 0 :(得分:0)

你写了模态而不是模型 尝试这个例子很棒!

  <ul>
    <li ng-repeat="person in peopledata" ng-init="$parent.selected = peopledata[0].jobs">
        <label>{{person.jobs}}
            <input type="radio" ng-model="$parent.selected" name="nameout" value="{{person.jobs}}"  required />{{$parent.selected}}
        </label>
    </li>
</ul>

https://jsfiddle.net/beentaken/ma86cz7u/