Mastering the use of expressions in ng-click and ng-show in AngularJS

I've been working on creating expandable rows within a table, but I'm encountering some issues. Despite not receiving any error messages, the functionality isn't behaving as expected. I suspect there might be an issue with how I'm using expressions with ng-show here. Check out my code on Plunker

Here's a snippet of my code:

<table class='table'>
    <thead>
      <tr>
        <th>name</th>
        <th>itemOne</th>
        <th>itemTwo</th>
      </tr>
    </thead>
    <tbody ng-repeat="data in tableData| orderBy:'-clintonValuemain'">
      <tr>
        <td>
          <button ng-show="data.expand" ng-click='data.expand = true'>+</button>
          <button ng-show="!data.expand" ng-click='data.expand = false'>-</button>
          <input type="checkbox" class='checkbox'>
          <a rel="noopener" target="_blank" href={{data.url}}>
        {{data.name}}
        </a>
        </td>
        <td>{{data.valueMain}}</td>
        <td>{{data.tValue}}</td>
        <tr>
          <tr ng-show="data.expand" ng-repeat="subs in data.subvalues| orderBy:'-clintonValuesub'" >
            <td>
              {{subs.name}}
            </td>
            <td>
              {{subs.valueSub}}
            </td>
            <td>
              {{subs.tValue}}
            </td>
          </tr>
        </tr>

      </tr>
    </tbody>
  </table>

Answer №1

Give this a try

<button ng-show="data.showContent" ng-click='data.showContent = true'>Show Content</button>
<button ng-show="!data.showContent" ng-click='data.showContent = false'>Hide Content</button>

Check out the updated plunker

https://plnkr.co/edit/sJDFAp1KDvhYh8K3q7z2?p=preview

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

Is there a way to prevent a page from automatically redirecting to another page without relying on user action or using the StopPropagation and window.onbeforeunload event?

function confirmExit(e) { var f = FormChanges(); //checking if the page has been modified if (f.length > 0){ if (submitForm == false) { if(!e) var e = window.event; e.cancelBubble = true; e.returnValue = "You ...

Having trouble getting ng-repeat to work properly alongside Bootstrap collapse?

Using a bootstrap 4 card to create a blog post. When the View Comments link is clicked, a collapsed div within the card-footer should open to display all comments. The collapse functioned correctly with hard coded html and dynamic data {{blog.title}} until ...

What is the best way to extract plain text with JQuery?

I found this Html code snippet: <div class="form-group row"> <label id="lb_size" class="col-lg-3 col-form-label"> <span class="must-have">****</span> Size </label> </div> My goal is to ext ...

Returning to the previous state in AngularJS when unchecking a checkbox

I'm a beginner when it comes to using angularjs HTML File: <div class='col-md-2 searchdisplay-col1' ng-controller="amenitiesController" style="margin-top:20px"> <h4>Amenities</h4> <label ng-repeat="facilityName ...

Using AngularJS and Web API to generate a dropdown menu from a one-to-many relationship

I have two tables in my database: People and Payband. Let me simplify the relationship below: dbo.People PersonId : int (Primary Key) FirstName : string MiddleInitial: string LastName : string DateOfBirth: datetime PaybandId : int (Foreign Key) dbo.Payb ...

Revamping the settings page by featuring a single "save changes" button

Is it possible to create a settings.php page where users can update their personal information, such as username, password, and email, all within the same page? I know how to perform these tasks individually, but I'm unsure about integrating different ...

Storing items in localStorage in the same order they were added

I am having an issue with sorting localStorage items by the order they were added. Despite my code working to add items to the localStorage array and display them as HTML, I am encountering a problem with the order of the items. When I add a 3rd item to t ...

How come the 'color' property in the material-ui TextField functions properly, while the 'borderColor' property does not work as expected?

I am trying to show a TextField in orange color: <TextField id={field_meta.name} label={field_meta.title} defaultValue={field_meta.value? field_meta.value: ""} onChange={this.handleChange} margin="normal" inputProps={{style: {bo ...

Utilizing ng-class with Boolean values in AngularJS

On my page, I have a pair of buttons that control the visibility of elements using ng-hide and ng-show. <a ng-click="showimage=true" ng-class="{ 'activated': showimage}" class="button">Images</a> <a ng-click="showimage=false" ng-c ...

How can I effectively handle extensive data parsing from a file using JavaScript?

Looking to optimize data parsing in JavaScript for a large file? I'm currently using JSON parse for a 250MB file, but it's too slow. Is there a faster method to extract a high volume of data without iterating through every character? The file con ...

How to eliminate excess white space on the right side in Bootstrap 4

Could someone please clarify why I am experiencing a white space on the right side when using Bootstrap 4? This is the primary code block for the page. <main id="intro" role="intro" class="inner text-center"> <h2>Lorem Ipsum</h2> ...

In Java, we can convert the ISO date format to the desired format

Is there a way to change the existing ISO Date format into a different required format? The current MongoDB Iso date is 2016-08-31T08:30:17.795Z The desired format needs to be: Aug 31, 2016 08:30 AM ...

ng grid shift select issue mistakenly selects extra rows

Take a look at my plunker here: link var app = angular.module('app', []); // encountering a silly error that prevents me from pasting the entire code, please refer to the plunker for details To replicate the issue: Click on the first row with ...

Switching between different elements in an array using React

I've got a collection of appointments and I need to create a React view that will show them one by one. Users should be able to navigate through the appointments using arrow buttons. Here's an example of what the data looks like: const arr = [ ...

What is the method for invoking a function with arguments within an HTML `<p>` element?

I am looking to display like and dislike percentages on cards. <v-card v-if="software[2] == searched || searched == ''" class="software-card" > <h3>{{ software[2] }}</h3> ...

When the button is clicked, update the text within the <script> tags utilizing jQuery, JavaScript, or PHP

Here is the code snippet where changeme represents the text that needs to be replaced upon clicking a button: The following HTML and JavaScript code demonstrates this functionality: 1) Any input provided by the user in the field will be captured, replaci ...

In order to access the localStorage from a different component, a page refresh is required as it is

UPDATE: Just to clarify, this question is NOT duplicate of how to retrieve the value from localstorage. My scenario is unique and the issue lies with Angular itself rather than localStorage. I am currently developing an Angular7 application. In one of my ...

The issue with Mongoose populate failing to populate

I'm facing an issue with populating my users' car inventory. Each car has a userId attached to it upon creation, but for some reason, the population process isn't working as expected, and no errors are being displayed. Let's take a loo ...

Inconsistent reliability of Loopback-context prompts the search for an alternative solution

After encountering some reliability issues with the loopback-context package, I decided to try an alternative approach. Instead of relying on setting the current user object in my middleware using loopback-context, I opted to fetch the accessToken from the ...

Error: Attempting to assign a value to 'onclick' property of null object [Chrome Extension]

window.onload = function() { document.getElementById('item_save').onclick = function() { var item_name = document.getElementById('item_name').value; var item_size = document.getElementById('item_size').value; v ...