Switching back and forth between different rows within a table

Currently, I am just starting out with AngularJS (1.5) and I have come across a challenge that I am hoping to get some assistance with. I have a table that is generated dynamically and for each row, I need to add a down arrow in the first column. Based on the selection of this arrow, I want to display the corresponding data in a separate div. At the moment, I can toggle the div visibility - clicking the arrow will open it and another click will close it. However, when I click on the arrow of the first row, details for all rows are being fetched instead of just the selected row. Any help on how to fix this would be greatly appreciated.

I've attempted to link the index of the selected row to fetch the correct details.

HTML File

<div>application
    <span class="glyphicon glyphicon-menu-down" data-toggle="collapse" ng-class="{'selected': $index == selectedRow}"
        ng-click="showAppDetails($index)"></span>
</div>

<div ng-if="selectedRow == index" ng-hide="!IsHidden">
    <p> hellop</p>
</div>

Controller.js

 $scope.IsHidden = false;
 $scope.selectedRow = null;
 $scope.showAppDetails= function(index){
     $scope.selectedRow = index;
      $scope.IsHidden = $scope.IsHidden ? false : true;

Answer №1

Here is the solution

<div ng-if="selectedRow == $index" ng-hide ="!IsHidden">

Answer №2

<table>
<tr ng-repeat="info in appDetails track by $index">
<div class="icon" ng-click="displayedInfo=info"></div>
</tr>
<div ng-if="displayedInfo != null">
  <p>{{displayedInfo}}</p>
</div>
</table>


displayedInfo=null;

This advice could be beneficial.

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

Prevent redirection in JavaScript

My current script is designed to detect an Android device and then redirect the user to "android.html". Once on the "android.html" page, the user has the option to either download an app or click "CONTINUE" to proceed to "index.html". However, there seems ...

AmCharts Axis renderer mistakenly renders an additional grid line

I have successfully created a basic XYChart using amcharts4. To get rid of the grid lines on the x-axis, I changed the stroke opacity for the x-axis grid to 0 using the following code: xAxis.renderer.grid.template.strokeOpacity = 0; Everything was workin ...

Error Panel Style Message Format:

Currently, I am utilizing PrimeFaces, which utilizes JQuery UI not just for its functionality but also for its CSS styling framework. The issue I am facing stems from my lack of understanding about the CSS framework, as I have been unable to locate any exa ...

What are some methods to prevent cookies from being overridden?

Just beginning my journey in web development. Currently utilizing asp.net Web API and Angular with token authentication. Every time a user logs in, I set the token in a cookie and send it with each request. Everything has been running smoothly so far, bu ...

Freshly updated, discover how to create an underlined navbar menu item

I'm trying to underline the currently selected menu item in a navbar, but I'm having trouble getting it to work. Here's my code: .navbar-nav .nav-item:focus .nav-link { text-decoration: underline; background-color: yellow; } It&apo ...

How can we utilize data retrieved from Mongodb in Express and pass it to a Jade view using the res.render function?

Within my node/express application, I need to pass data retrieved from mongoose to my jade view. The code below in routes.js accomplishes this task: app.get('/newrequest', function (req, res) { Account.find({}, function (err, data) { ...

I am having trouble connecting my CSS file to my EJS file

I'm having trouble including my external main.css file in my header.ejs file. I've designated my CSS file as public in my backend Node.js with Express.js server (index.js) using this static code: app.use(express.static("public")); The ...

Ways to display encoded URL image using <img src>

I have a scenario where I am dealing with a URL of an image link location that does not have a file extension like .jpg, but when accessed it displays the corresponding image. How can I output this URL in PHP? For instance, take the example of the reCAPTC ...

Developing a slideshow with PHP and JQuery

Attempting to create a simple manual slideshow where the user clicks "next" to advance to the next slide. I have over 50 images and want to display them in batches of 8. For example, the first batch of 8 will be shown initially, then the user can click "ne ...

Is it possible for the *ngIf directive to stop unauthorized users from accessing my admin page through their browsers?

When the *ngIf directive is set to false, a certain element or component will not be included in the DOM. For example, let's say there is a component that displays admin tools and should only be accessible to authorized users (administrators). Will se ...

"Assigning a CSS class to determine the length of a List in a JSP

In my JSP code, I have a list called ${contentList} that contains product information such as product images, names, and prices. To display this data in an HTML table using JSP, I want to dynamically set the class of the first table row based on the numbe ...

Two selection options controlling filters. The first choice influences the data shown in the second filter

I've been struggling for hours to figure out how to build this functionality. My code seems to be getting close, but I'm having trouble passing my selection from the HTML back to the controller. Here's my Angular code: var Categories = Pa ...

Sending information and HTML content from PHP to JavaScript using JSON

As a beginner to this, I acknowledge any noticeable mistakes. I am attempting to utilize an ajax call from Javascript to randomly select a movie from a database, generate some html containing information about the movie, and also return an array of inform ...

The navigation bar extends beyond the container

First time diving into bootstrap and struggling with my items overflowing the container. Here's a snippet of my code: <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta http-equi ...

Improving JavaScript function by restructuring and eliminating conditional statements from within a loop

Looking for advice on how to refactor my function and eliminate the if statement inside the loop. Any suggestions would be helpful as I suspect the else condition is unnecessary. function quantitySum(array) { let sum = 0; for (let i = 0; i < array ...

Combining two arrays to create a new object: a step-by-step guide

Assuming I have two arrays as follows: let arr1=["john","Bruce","Clent"]; and let arr2=[55,33,22]; How can I create an object using these arrays in JavaScript? The object should look like: {"john":55,"Bruce":33,"Clent":22}; It should use arr1 to define th ...

Enable AJAX to dynamically load pages without caching

I am currently using an ajax function to refresh a specific division on a webpage with HTML content. <script> $('#scene_container').load('scene.html', function () { cache: false }); </script> ...

What is the best way to obtain the full URL in a live environment?

I'm currently encountering an issue where I am unable to obtain the absolute URL in the production build when using getStaticPaths and getStaticProps. export async function getStaticPaths() { const url = process.env.NODE_ENV === "developmen ...

"Discovering a button press using the Gamepad API: A Step-by-Step Guide

I'm currently building a web page that can detect button presses on an Xbox controller and display a boolean value based on the pressed button. Right now, I have successfully managed to detect when a controller is connected and show it as a string. Ho ...

Generating a collection of objects using arrays of deeply nested objects

I am currently working on generating an array of objects from another array of objects that have nested arrays. The goal is to substitute the nested arrays with the key name followed by a dot. For instance: const data = [ id: 5, name: "Something" ...