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

javascript - How to insert new line within ng-repeat of the middle (Angularjs + twitter bootstrap + jade) - Stack Overflow

programmeradmin3浏览0评论

I want to insert new line like a following.

div.row
  div.span12
    div(ng-repeat="(data in datas)")
      p data.text

      // insert new line when $index is the number divisible by 3.

how does it do?

thank you.

I want to insert new line like a following.

div.row
  div.span12
    div(ng-repeat="(data in datas)")
      p data.text

      // insert new line when $index is the number divisible by 3.

how does it do?

thank you.

Share Improve this question asked Jul 21, 2013 at 3:56 tonpatonpa 211 gold badge1 silver badge2 bronze badges 1
  • Can you include some examples of what you have tried and show the desired output? – Ro Yo Mi Commented Jul 21, 2013 at 4:18
Add a ment  | 

2 Answers 2

Reset to default 5

You can use the ng-if directive, you would show a line break every time your $index matches a certain condition. So if you'd like to break after 3 iterations:

<div ng-repeat="data in datas">
    {{ data }}
    <br ng-if="($index+1)%3==0">
<div>

I am not sure what your end result will be, but there are a few ways that I would approach this. The first is to use ng-hide and ng-show to do something different on items that are divisible by 3. The other way would be to use ng-class to just style the 3rd element differently.

<div ng-repeat="data in datas">
    <div ng-class="{'red': ($index+1)%3==0}">{{data}}</div>
<div>

Here is a jsFiddle

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论