Tips for effectively segregating various elements within an ng-repeat loop

I'm in the process of creating a website that utilizes ng-repeat to showcase two directives and an element. The second directive and the element are displayed after a certain number of "repeats" (determined by index). These directives appear as rectangular cards, arranging themselves from left to right until they fill up the screen, then moving on to the next line. The screenshot below illustrates this layout:

https://i.sstatic.net/NRSI0.png

In the image, the white rectangles represent the first directive, while the black rectangles signify the second directive and element. However, I'm encountering an issue where if the black rectangle is meant to be the first item on a new line, it ends up displacing the last white rectangle from the previous line and appearing before the black rectangle on the following line. Essentially, the two directives within the ng-repeat loop seem to be sticking together instead of separating when there isn't enough space for both on one line. Here's an example to clarify my point:

https://i.sstatic.net/JM0Nz.png

Now, let's take a look at my code. Below is the HTML snippet 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" gt;if="!(($index + 1) % adFrequency)"></ad-info>
    <div class="ad-spacing" ng-if="!(($index + 1) % adFrequency)"></div>
</div>

The card-info directive (representing white rectangles) appears every time, whereas the ad-info directive (representing black rectangles) only shows up at intervals determined by adFrequency.

Next, here's the CSS I've implemented using LESS:

.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;
}

Is there a way to "unbundle" these elements so that they don't get grouped together?

Note: I attempted to create a JSFiddle, but due to the complexity and size of the project, I couldn't get everything to function correctly. I've trimmed down the content as much as possible to simplify this post.

Answer №1

If you want to iterate through a list in AngularJS, consider using ng-repeat-start and ng-repeat-end.

For example:

<div ng-repeat-start="item in items" class="repeated">
    <item-component class="item" item="item" ng-style=""></item-component>
</div>
<div ng-repeat-end class="repeated" ng-if="!(($index + 1) % frequency)">
    <ad-component class="ad-style"></ad-component>
    <div class="ad-spacing"></div>
</div>

For more information, check out the documentation here

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Navigating the complexities of applying CSS exclusively to child grids within Kendo Angular may seem challenging at first

This image illustrates the grid layout I have created an angular UI using kendo that features a nested grid. I am trying to apply CSS specifically to the child grid without affecting the parent grid. However, no matter what CSS I write, it ends up being a ...

Animating Elements with CSS and HTML

Struggling with my website project, specifically creating a login page. The issue arises when resizing the browser, causing elements to look misaligned and chaotic. Before: view image here After: view image here /* Bordered form */ form { margin-l ...

Dynamic Data Visualization: Implementing smooth transitions to update a plot when the dataset's x-axis scale is modified

I encountered some issues while working with a Histogram chart using d3, as demonstrated in this example. After plugging in my data, I noticed strange side effects such as retained information from previous datasets on the x-axis scale even after refreshin ...

Guide to executing multiple AJAX requests within a single Django view

As I develop my personal spending diary, I encountered a dilemma. To enhance the user experience, I aim to streamline the process of adding new items without refreshing the page. Although I created a single ajax form, I now realize the necessity for two ...

The HTML embed element is utilized to display multimedia content within a webpage, encompassing

Currently, I am working on a static website for my Computer Networks course. Students need to be able to download homework files in PDF format from the website. I have used embed tags to display the files online, but I'm facing an issue where the embe ...

Styling the navigation menu for mobile devices

How can we transition from a menu like this : https://i.sstatic.net/qQ2k1.png to this when the screen size reaches a specific width: https://i.sstatic.net/AUM4v.png In essence, replacing certain texts with icons. Is pre-defining it and changing the dis ...

Guide on efficiently utilizing ui-select within the ng-repeat directive

My ui-select element is wrapped in an ng-repeat directive, causing a scope-related issue. This results in a few problems: Once a value is selected in the first select, the second select is automatically populated with the same value. The placeholder ...

I am eager to design a form input field within the vuetify framework

https://i.sstatic.net/zbCfI.png I'm having trouble creating a text field in Vuetify where the button and height are not behaving as expected. I've attempted to adjust the height multiple times without success. Although I have the necessary CSS, ...

Avoid passing down line-height settings to elements within nested elements

Is there a way to prevent the span styled with font-size: 12px from inheriting the line-height of the span styled with font-size:18px? I need the line-height value to be 1.5 for both 18px and 1.5px font sizes, but I am unable to separate the two spans. ht ...

Relocate a table beside an image

Check out the layout of my webpage: ------------- ------------- Image here ------------- ------------- Table1 here Table2 here Table3 here My goal is to redesign it to look like this: ------------- ------------- Image here Table1 here - ...

Steps for Deleting Browsing History in Adobe Air's HTML Control

In my desktop application, I am utilizing Adobe AIR's html control to enable users to browse web pages. I have been using the html.historyBack() and html.historyNext() methods for navigation, but I am facing a challenge. I want to clear the history wh ...

Utilizing AngularJS 1.X to implement filters on transformed information

When using the combination of ng-repeat and a filter, it creates a highly effective search function. However, once the data is converted, the use of a filter for searching becomes limited. For Instance JavaScript $scope.ints = [0,1,2,4,5,6,7,8,9, ..., 9 ...

Methods for testing a contenteditable division with Angular end-to-end testing

I'm attempting to assign a value to a content-editable div using an Angular end-to-end test. Here's the snippet of code: it('compare value - Launch form', function() { element('#firstLine').val(123) ...

Compatibility Problem with Form Inputs in Internet Explorer 7 when Using a jQuery Datepicker

I've encountered a frustrating issue with my Reservations area (jquery ui datepicker) on the site I'm currently working on. When viewed in IE7, the datepicker is broken and displayed on separate lines. If you'd like to check it out yourself ...

Eliminating an undesired gap that exists between two ul li elements

Seeking assistance urgently. Any tips on eliminating the annoying small space that separates my 2 UL LI lists? I have a hunch it might be related to the <dd> tag, but pinpointing the exact issue is proving tricky. Check out this visual representati ...

Tips for canceling an http request in angularjs when the requesting controller has exited its scope

Developed a custom angularjs application with ng-view for loading four different modules using route provider. Each module makes HTTP requests as shown below: var requestManager = { "locations": {}, "employees": {}, "items": {}, "templates ...

What is the best way to position one div above another div?

I'm struggling to move the div containing the product name, amount, price, and total to the top of its parent div. Changing the position and vertical alignment properties have not been effective. I've attached a screenshot of the page where the b ...

What is preventing my code from locating the AngularJS $interval functionality?

Having an issue with my AngularJS Code when trying to call $interval in VS2013. The error message says it is not found. Here's the code snippet: var appRun = [ '$rootScope', function ( $rootScope ) { // This ...

Changing the position from fixed to static

It's strange, but for some reason when I attempt to apply position:fixed using jQuery: $('#footer').css('cssText', 'position:fixed !important;'); to my footer, the result on the page is different: <div id="footer" ...

Maximizing the potential of Angular forms through native FormData

Currently, I am revisiting an older project that still uses traditional methods for form submission. The HTML includes a form element with defined method and action. My goal is to submit the form in the old-fashioned way using the action attribute to post ...