Display or conceal nested divs within ng-repeat loop

I set up a div with sub divs to establish a nested grid system. There are three levels altogether:

  1. MainDiv - Always Visible
  2. SecondDiv - Display or conceal when MainDiv is clicked on
  3. ThirdDiv - Display or conceal when SecondDiv is clicked on

    <div class="container padding" style="background-color: #fff;" ng-controller="MyCtrl">
        <div class="row">
            <div class="col col-75" >
                Department / Product Type
            </div>
            <div class="col col-25">
                Qty
            </div>
        </div>
    
        <div ng-repeat="item in departments | orderBy:'-qty'" style="padding:0px;margin: 0;">
            <div class="row" ng-class-odd="'odd'" ng-class-even="'even'">
                <div class="col col-75" style="padding:0;margin:0;">
                    {{item.departmentName}} - {{item.productTypeName}} - Click here for more details
                </div>
                <div class="col col-25" align="center" valign="middle" style="font-size: 14px;font-weight:bold;padding:0;margin:0;">
                    {{item.qty}}
                </div>
            </div>
            <div ng-repeat="style in item.styles" style="padding:0;margin: 0;">
                <div class="row">
                    <div class="col" style="margin-left: 5% !important;border-top-width:0;border-bottom-width:0;">
                        {{style.styleNum}} ({{style.qty}}) - Click here for more details
                    </div>
                </div>
                <div class="row" ng-attr-id="{{ 'level-2-' + $index }}">
                    <div class="col col-5" style="border:0"></div>
                    <div class="col col-5" style="border-left:0;border-bottom:0;border-right:0;"></div>
                    <div class="col col-25">Color</div>
                    <div class="col col-25">Size</div>
                    <div class="col">Product#</div>
                </div>
                <div ng-repeat="styleLine in style.details">
                    <div class="row">
                        <div class="col col-10" style="border:0;"></div>
                        <div class="col col-25">{{styleLine.color}}</div>
                        <div class="col col-25">{{styleLine.size}}</div>
                        <div class="col">{{styleLine.productNum}}</div>
                    </div>
                </div>
    
            </div>
        </div>
    </div>
    

Now I want to include a click event on the div to toggle the display of the necessary nested divs.

Plunker: http://plnkr.co/z3RiV6cDFC6YjrbuqxN9

Answer №1

Illustrative demonstration of utilizing ng-init and ng-click:

<div ng-repeat="item in collection" ng-init="display = false">
    <div ng-click="display = !display"></div>
    <div ng-repeat="subitem in item.children" ng-show="display">
        <p>Greetings Earthlings!</p>
    </div>
</div>

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

Encountering a problem when attempting to open a model dialog in AngularJS

I'm looking to implement a modal dialog in my project, but I seem to be encountering some issues. Here's what my HTML code looks like: <div ng-controller="bodyController"> <!-- This html would live at the path specified in the contr ...

Mastering form reset functionality using jquery

When attempting to register, an error is generated if any field is left blank in the form (from PHP). The input fields that have been filled out are retained using Smarty: {if isset($smarty.post.registratie.naam)} value="{$smarty.post.registratie.naam}"{el ...

No element found with the specified exportAs value of "ngForm" on the <form> tag

I am currently experimenting with a template driven form in Angular, but I encountered an error stating **There is no directive with “exportAs” set to “ngForm"** I have made sure to import FormsModule and ReactiveFormsModule in app.module.ts as well ...

Tips for choosing elements in JavaScript using querySelector even after they've been included in the code using innerHTML

Within the scenario below, a parent element is present in the HTML code and the span element with a class of 'child' is nested within the parent element using the createChild function. Subsequently, the content of the child element is modified el ...

Finding a JSON file within a subdirectory

I am trying to access a json file from the parent directory in a specific file setup: - files - commands - admin - ban.js <-- where I need the json data - command_info.json (Yes, this is for a discord.js bot) Within my ban.js file, I hav ...

Include the component with the function getStaticProps loaded

I am currently working on a project using NextJs and I have created a component to load dynamic data. The component works fine when accessed via localhost:3000/faq, but I encounter an error when trying to import the same component into index.js. It seems l ...

Issues with closing Foundation 6 off-canvas feature

Here is a link that I have: If you click on the skip button in the middle, it will take you to the next slide where Foundation 6 off-canvas is implemented. The header containing the toggle button for the off-canvas menu is located outside of the menu its ...

Adjust the size of an Angular component or directive based on the variable being passed in

I'm looking to customize the size of my spinner when loading data. Is it possible to have predefined sizes for the spinner? For example: <spinner small> would create a 50px x 50px spinner <spinner large> would create a 300px x 300p ...

Arrange the bootstrap columns in a grid layout both vertically and horizontally adjacent to one another

I need help with displaying my columns in this specific layout https://i.stack.imgur.com/2hzju.jpg Code <div class="row"> <div id="id-orders-stats" class="col-md-6 col-sm-6"> </div> <div class="col-md-6 col-sm-6 stats-box"&g ...

Accessing the JSON file from the Google Maps Places API using either JavaScript or PHP

In the midst of developing an application, I am working on fetching a list of places near a specific latitude and longitude. After obtaining an API key, inputting it into the browser URL successfully retrieves a JSON file containing the desired places dat ...

Encountering a "Connection Refused" error when attempting to test a React and Express application

Currently, I am developing an order system using React for the frontend (port 3000) and Express for the backend (port 3001). Everything functions perfectly when tested on the same MacBook that hosts the node project. However, when testing it on a differen ...

Organize the array following the guidelines of a card game with a versatile approach

deck = ['Jack', 8, 2, 6, 'King', 5, 3, 'Queen', "Jack", "Queen", "King"] <!- Desired Result = [2,3,5,6,8,'Jack','Queen','King'] Explore the challenge: Arrange the ...

Safari failing to show SVG at correct alignment

I am looking to implement a unique feature on my website where image placeholders are displayed for 1 second before fading out to reveal the actual image. These image containers will be responsive, adjusting to fit the size of their parent container. In a ...

Leveraging jQuery to extract a key-value pair and assign it to a new property by

I'm struggling with extracting a value from a key-value pair and inserting it into the rel property of an anchor tag. Even though I try to split the code and place the value correctly, it doesn't seem to work as expected. Instead of applying the ...

Difficulty displaying data from PapaParse in VueJS despite successful retrieval in console

My first attempt at using PapaParse is running into some issues. I am successfully parsing a remote CSV file and storing the data, as confirmed by console.log. However, when I try to output it with a v-for loop, nothing seems to be working. To achieve thi ...

What is the best way to execute an inline function two times in a row

I'm currently utilizing Gametime.js to create a real-time world chat feature. All messages are kept in a database for storage. Interestingly, PubNub, which is used by Gametime.js, seems to require messages to be sent twice for them to actually go th ...

If tall, then the height is set to 100%; if wide, then the width is set

My image-generating algorithm produces images of various sizes, some tall and some wide. How can I ensure that the images always fit perfectly within their parent container? They should be 100% height if they are tall and 100% width if they are wide. .im ...

Float from the bottom and then rise up

I'm attempting to use CSS to make code from further down in the HTML appear above code from a section above it. Here is how my HTML structure looks: <div class="showbelow"> show below </div> <div class="showabove"> show above < ...

Challenge with constructing HTML structures

I created a table in HTML: <table cellpadding="0" cellspacing="0" border="0" style="width:1000px" id="maintable"> <thead> <tr> <th class="asc" width="30"><h3>ID</h3></th> <th width="200">&l ...

The dynamic design of the webpage allows for a fluid layout, where the navigation bar smoothly adjusts its position when

I anticipate receiving criticism from certain users for not conducting enough research. However, I have dedicated two days to this issue and the lack of guidance is starting to frustrate me. Therefore, I offer my apologies if this question has already been ...