Creating an accordion feature within an ng-repeat using AngularJS based on user clicks

When I click on the span with

ng-click="click_subcat(opp.ct_nm);
, the content is loaded within the
<span ng-click="click_pdms(opp.sbct_nm);" style="color:white;cursor:pointer">{{opp.sbct_nm}}</span>
. The issue arises when I click on that span as everything loads in
<span ng-click="click_pdms(opp.sbct_nm);" style="color:white;cursor:pointer">{{opp.sbct_nm}}</span>
.

Check out the code below: (Before Click) https://i.sstatic.net/oNp3O.png (After Click) The same content loads in every category. I want electronics to display laptops and mobile devices, not fashion items. https://i.sstatic.net/DZSxl.png

<div id="mySidenav" class="sidenav" >
                <a href="javascript:void(0)" class="closebtn" onclick="closeNav()">&times;</a>
                <a ng-click="click_subcat(opp.ct_nm);">{{opp.ct_nm}}</a>
                <a ng-repeat="opp in res">
                    <span ng-click="click_subcat(opp.ct_nm);" style="color:white;cursor:pointer;font-size:60px;" class="accordion">
                        {{opp.ct_nm}}

                        <ul ng-repeat="opp in inp">
                            <li>
                                <span ng-click="click_pdms(opp.sbct_nm);" style="color:white;cursor:pointer">{{opp.sbct_nm}}</span>
                            </li>
                        </ul>
                    </span>
                </a>
            </div>

Answer №1

Just introduced a new array called $scope.hiddenDiv = [] in order to display the div based on the index of the main $scope index.

$scope.click_subcat = function (btnval,index)
    {
        var responsed;
        $scope.hiddenDiv = [];
        var urlg = 'http://localhost/Publish/ProductSubCategory/GET?sbct=' + btnval;
        $http.get(urlg).then(function (responsed)
        {

            $scope.hiddenDiv[index] = !$scope.hiddenDiv[index];
            $scope.inp = responsed.data;
        });
    };

Additionally, included another div to control its visibility as true or false.

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

The lite-server package from npm seems to be ignoring any updates made to the CSS files

I'm currently working on the Angular 2 tour of heroes tutorial application. I have run into an issue where even though I am compiling my SASS files to generate CSS, the lite-server does not recognize this change and therefore does not refresh the brow ...

Managing Chrome application authentication pop-up with Selenium Webdriver and C#

https://i.sstatic.net/lPbCv.png I have come across numerous discussions on this matter but none of the solutions seem to be effective. I am looking for a way to input the username and password into the chrome authentication alert using Selenium Webdriver ...

The output stored in the variable is not appearing as expected

https://i.sstatic.net/VWCnC.pnghttps://i.sstatic.net/UoerX.pnghttps://i.sstatic.net/n52Oy.png When retrieving an API response and saving it in the "clima" variable, it appears as undefined. However, when using console log, the response.data is visible ...

Checking URL validity using JavaScript Regex

I attempted to validate a URL with or without the http protocol, but no matter what I tried, the function kept returning false. I verified my regex string on this website: And it appeared as expected. function isUrlValid(userInput) { var rege ...

Tips for successfully passing ExpressJS locals variable to an EJS template and utilizing it as a parameter when invoking a JavaScript function during the onload HTML event

const hostname = "192.168.8.154"; const port = 3002; app.use('*', function (req, res, next) { db.collection('sys_params').find().toArray() .then(sysParams => { //console.log(sysParams); app.locals.sysParams ...

"Exploring the process of obtaining a compilation of Materialize CSS chip elements within an AngularJS framework

<div ng-repeat="job in jobList" > <div class="chip" id="jobchip" ng-model="jobchip"> <label for="jobchip"> Available Jobs</label> {{job.Name}} <i class="close material-icons">close</i> < ...

Identifying when several asynchronous JavaScript $.ajax requests have finished

I have a JavaScript function that runs a loop and makes asynchronous AJAX calls. I need to wait for all the AJAX calls to complete before updating the UI. Here is the loop: function sync_SyncLocalStorageToServer() { if (helper_IsAppOnline()) { ...

The reflight response received an unexpected HTTP status code of 500

Recently, I've been working on utilizing the Yelp Fusion API by making a simple ajax call. I started off by using the client_id and client_secret provided by Yelp to successfully obtain an access token through a 'POST' request in Postman, fo ...

What is the best way to send a variable using $.post in a JavaScript script?

My jQuery and Javascript code below is responsible for handling the ajax request: else { $.post("http://www.example.com", {email: val}, function(response){ finishAjax('email', response); }); } joi ...

Use Ramda to convert an array of objects into nested objects

As a beginner, please forgive me for asking what may be considered a naive question. I currently have an array of objects const arr = [{id: 1, name: 'Pete'}, {id: 5, name: 'John'}, {id: 3, name: 'Peter'}] and I am looking to ...

Leveraging JavaScript to create a horizontal divider

Just a quick question - how can I create a horizontal line in Javascript that has the same customization options as the HTML <hr> tag? I need to be able to specify the color and thickness of the line. I am working on a website where I have to includ ...

linking to a page that shows the user's chosen option from a dropdown menu

One of the challenges I encountered was creating a feature that allows users to share a specific selection from multiple dropdown lists on a page. Essentially, my goal was to enable users to send a link that would direct others to the same page with the ex ...

Looking to personalize the MUI - datatable's toolbar and place the pagination at the top?

I successfully managed to hide the toolbar icon, but I am struggling with positioning pagination from bottom to top. Additionally, I am attempting to add two buttons (reset and apply) in the view-Column toolbar without any success in customizing the class. ...

Guide to forming an array by extracting specific properties from a nested JSON array using javascript

Currently, I have this list: list = { id: 1, arr: [ {index : 1 , description: "lol" , author: "Arthur"}, {index : 2 , description: "sdadsa" , author: "Bob"}, {index : 3 , desc ...

Retrieving AJAX data in a Node.js environment

In my HTML application, I am utilizing AJAX to showcase the output on the same page after the submit button is clicked. Before submitting, I am able to retrieve the values passed in the HTML form using: app.use(express.bodyParser()); var reqBody = r ...

AngularJS smart-table / Single row selection

I'm trying to create selectable table rows in smart-table. Using st-select-row="row" and st-select-mode="single" However, I want a selected row to remain selected until the next row is clicked. Currently, when I click on links that open in a new w ...

Repairing the Left-sided Popup Leaflet

Can someone help me with fixing the positioning of the Popup to the left of the map? Currently, it does not stay aligned to the left edge when moving the map. I tried using position: fixed in my styling, and while everything looks good when zooming, it br ...

What is the best way to combine PHP and HTML within a JavaScript script?

I'm facing a challenge with integrating dynamically added elements and a populated drop down on my form. Is there a way to combine the two seamlessly? Below is the code snippet I'm using for dynamically adding and removing elements: $(docu ...

AngularJS not swapping the data-url with the scope URL provided in {{ uploadUrl }}

Currently, I am utilizing jQuery fileupload to send a file to a specific URL. Within my controller, the code snippet below demonstrates how I generate the URL for uploading: uploadService.getUploadURL($scope.projectId).then(function (url) { $scope.up ...

Bringing custom JavaScript functions into a Vue.js component

In my Vue.js project, I have an abundance of Javascript processing that is all local and doesn't require server-side functionality. I'm exploring the possibility of importing a file containing specific processing functions (such as mathematical a ...