最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Using angularjs to create horizontal radio buttons - Stack Overflow

programmeradmin4浏览0评论

I am building a set of radio buttons using the ngRepeat directive and I need to make it horizontal. I'm not sure it's possible to do that with ngRepeat, since each instance gets its own scope. The below structure creates a new div for each item in the options array and they're displayed vertically.

<div ng-repeat="option in options">
    <input type="radio" role="radio" />
    <span>label</span>
</div>

Does anyone know any tricks for creating horizontal radio buttons?

I am building a set of radio buttons using the ngRepeat directive and I need to make it horizontal. I'm not sure it's possible to do that with ngRepeat, since each instance gets its own scope. The below structure creates a new div for each item in the options array and they're displayed vertically.

<div ng-repeat="option in options">
    <input type="radio" role="radio" />
    <span>label</span>
</div>

Does anyone know any tricks for creating horizontal radio buttons?

Share Improve this question asked Sep 29, 2013 at 19:55 JennieJennie 111 silver badge3 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 6

Angular doesn't really affect style in this way. Give your div float:left or display:inline-block in its style.

It should be noted that AngularJS from version 1.1.6 up allows one to do this much more cleanly:

Assume

$scope.data = [{val:0,txt:'Foo'},{val:1,txt:'Bar'},{val:2,txt:'Baz'}];

then you can use repeat-start and repeat-end like this:

<input ng-repeat-start="item in data" type="radio" value="{{item.val}}">
<span ng-repeat-end>{{item.txt}}</span>

Demo here: http://jsfiddle/rWLfZ/

发布评论

评论列表(0)

  1. 暂无评论