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
2 Answers
Reset to default 5You 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