如何在ng-repeat中分离多个元素?

第三纪

我正在制作一个使用ng-repeat来显示两个指令和一个元素的网站。第二个指令和元素都显示在x个“重复”(使用索引)的后面。这些指令是矩形卡,从左到右显示,直到屏幕显示满,然后移动到下一行,如以下屏幕快照所示:

正确放置

The white rectangles being the first directive and the black rectangles being the second directive and element. The problem I'm facing is that if the black rectangle is supposed to be the first item on a new line it will remove the last white rectangle from the line above and show up before the black rectangle on the next line. Really what's happening is the two directives inside of the ng-repeat are getting bundled together and not separating when there isn't space on one line for both of them. Here is an example of what I mean:

在此处输入图片说明

Alright, so on to my code. This is my html for the ng-repeat.

<div ng-repeat="acqui in acquis" class="repeated">
    <card-info class="card" acqui="acqui" ng-style=""></card-info>
    <ad-info class="ad-style" ng-if="!(($index + 1) % adFrequency)"></ad-info>
    <div class="ad-spacing" ng-if="!(($index + 1) % adFrequency)"></div>
</div>

As you can see, the card-info directive (white rectangles) shows up every time, while the ad-info directive (black rectangles) only show up every adFrequency number of times.

Here is my CSS. I am using less, so it's formatted a bit differently:

.card {
    .shadow;
    width: 350px;  
    height: 530px;
    display: inline-table;
    background-color: white;
    background-size: 100%;
    background-repeat: no-repeat;
    margin: 0 10px 20px 12px;
}
.ad-style {
    position: relative;
    .ads {
        position: absolute;
        .shadow;
        width: 350px;  
        height: 530px;
        display: inline-table;
        background-color: black;
        margin: 6px 0 0 8px;
    }
}
.ad-spacing {
    width: 350px;
    display: inline-table;
    margin: 0 10px -5px 10px;
}

有什么办法可以使我“解开”这些捆绑包吗?

注意:我尝试制作一个jsfiddle,但是该项目太大了,无法完成所有工作。我已经尽可能地删除了,所以我可以发表这篇文章。

金祖国

您可以尝试使用ng-repeat-startng-repeat-end

就像是:

<div ng-repeat-start="acqui in acquis" class="repeated">
    <card-info class="card" acqui="acqui" ng-style=""></card-info>
</div>
<div ng-repeat-end class="repeated" ng-if="!(($index + 1) % adFrequency)">
    <ad-info class="ad-style"></ad-info>
    <div class="ad-spacing"></div>
</div>

在这里您可以阅读更多https://docs.angularjs.org/api/ng/directive/ngRepeat

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

如何在Microsoft Azure流分析上从多个设备中分离数据

来自分类Dev

ng-repeat:如何在select中设置多个属性

来自分类Dev

如何在ng-repeat中进行ng-repeat?

来自分类Dev

如何在angularjs中分离Controller文件

来自分类Dev

如何在Firebase中分离用户角色?

来自分类Dev

如何在iPhone中分离JSON响应

来自分类Dev

如何在PHP中分离数组

来自分类Dev

我如何在Jframe中分离Jpanel

来自分类Dev

如何在Xcode中分离文件类

来自分类Dev

如何在angularjs中分离Controller文件

来自分类Dev

如何在JavaScript中分离数组

来自分类Dev

如何在linux中分离/boot分区?

来自分类Dev

如何在php中分离数组?

来自分类Dev

如何在ng-repeat期间呈现{{}}?

来自分类Dev

如何在多个元素上使用相同的ng模型

来自分类Dev

如何在ng-repeat中使用ng-if?

来自分类Dev

如何在ng-if中传递ng-repeat变量?

来自分类Dev

递归迭代ng-repeat时如何在ng-include中获取父元素

来自分类Dev

如何在一个ng-repeat中添加多个ng-repeats?

来自分类Dev

用ng-repeat重复多个元素

来自分类Dev

如何通过另一个表从列中分离出多个值?

来自分类Dev

如何从矩阵中分离行?

来自分类Dev

如何从数组中分离信息?

来自分类Dev

如何从数组中分离项目?

来自分类Dev

如何从if中分离出for循环

来自分类Dev

如何在ng-repeat中仅为一次迭代添加动态span元素?

来自分类Dev

如何在由ajax调用填充的ng-repeat中找到元素

来自分类Dev

如何在ng-repeat中一次显示元素

来自分类Dev

AngularJs指令:如何在ng-repeat元素上动态设置属性