如何使用ng-repeat将项目附加到同一行或行

时间:2013-08-21 06:05:19

标签: angularjs angularjs-ng-repeat

我想用ng-repeat将项目附加到同一行,但它似乎在新行上添加项目。在下面的示例中,我希望它们位于同一行,如:

“约翰25岁。杰西30岁。约翰娜28岁。”

结果是:

25岁的约翰  30岁的杰西  约翰娜,28岁。

我该如何实现?

<div ng-init="friends = [
  {name:'John', age:25, gender:'boy'},
  {name:'Jessie', age:30, gender:'girl'},
  {name:'Johanna', age:28, gender:'girl'}
]">


<div ng-repeat="friend in friends">
    {{friend.name}} who is {{friend.age}} years old.
</div>

1 个答案:

答案 0 :(得分:10)

试试这个

<div ng-repeat="friend in friends" style="float:left">
   {{friend.name}} who is {{friend.age}} years old.
</div>

OR

<span ng-repeat="friend in friends">
    {{friend.name}} who is {{friend.age}} years old.
</span>

默认情况下DIV呈现为display:blockSPAN呈现为display:inline