Activate ng-show when there are updates to the JSON data

I'm currently working on a feature where I need to hide the upload button and display a new edit button once the user uploads a file. My project involves using both angular-file-upload and md-data-table libraries. To achieve this, I have implemented a test function that saves the row that was clicked. After uploading the file, I update the 'uploaded' value within the JSON object. Despite successfully changing the value to true in the user_doc JSON object, the buttons in the HTML do not hide as expected.

Here's an excerpt of my HTML code:

<md-table-container>
    <table md-table multiple ng-model="selected">
        <thead md-head md-order="query.order">
            <tr md-row>
                <th md-column><span class="settings-header">Document Type</span></th>
                    <th md-column><span class="settings-header actions">Actions</span></th>
            </tr>
        </thead>
        <tbody md-body>
            <tr md-row md-select-id="id" md-auto-select ng-repeat="row in options">

                <td md-cell>{{row.name}}</td>
                <td md-cell class="buttons-cell" ng-show="!uploaded">
                <div ng-if="uploader">
                    <label for="key" class="md-button profile-upload" ng-click="test(row)" ng-if="!uploaded"><i class="material-icons">file_upload</i></label>
               <!-- <label for="key" class="md-button profile-upload" ng-click="test(row)" ng-if="uploaded"><i class="material-icons">PERP</i></label> -->
                    <input class="ng-hide" id="key" type="file" nv-file-select uploader="uploader" ng-if="!uploaded">
                </div>
            </td>
         </tr>
    </tbody>
</table>

Snippet from the controller:

$scope.uploader = new FileUploader();
let row_selection;

$scope.test = function(row,fileItem){
  console.log(row.id);
  row_selection = row;
}
$scope.uploader.onAfterAddingFile = function(fileItem) {
  if(fileItem.file.type === 'image/png' || fileItem.file.type === 'image/jpeg'){
      row_selection.uploaded = true;
  }else{
      showAlert();
  }
}
$scope.user_doc = {
    documents: {
        options: [
            {"id":"01","name":"ID Card","uploaded":false},
            {"id":"02","name":"Proof of Address","uploaded":false},
            {"id":"03","name":"CURP","uploaded":false}
        ]
    }
};
$scope.options = $scope.user_doc.documents.options;

Answer №1

To update the values in ng-repeat with those from row.uploaded, simply replace them as shown below:

<tr md-row md-select-id="id" md-auto-select ng-repeat="row in options">    
                <td md-cell>{{row.name}}</td>
                <td md-cell class="buttons-cell" ng-show="!row.uploaded">
                <div ng-if="uploader">
                    <label for="key" class="md-button profile-upload" ng-click="test(row)" ng-if="!row.uploaded"><i class="material-icons">file_upload</i></label> 
                    <input class="ng-hide" id="key" type="file" nv-file-select uploader="uploader" ng-if="!row.uploaded">
                </div>
            </td>
         </tr>

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

Error detected when interpreting JSON data in C#

I am currently studying C# and attempting to make the code below parse an incoming JSON recipe string that I convert into an XML document. However, I am encountering the following error: at System.Text.Json.ThrowHelper.ThrowJsonReaderException(Utf8JsonR ...

The variable 'X' in Node.js is not been declared

I've been struggling with this problem, trying to fetch my most recent tweets as an array using the npm module https://github.com/noffle/latest-tweets. However, no matter how I approach it, I always encounter errors such as 'posts is not defined& ...

Issues have arisen with the execution of JavaScript code inside a callback function

When the warnBeforeNew variable is set to false in the JavaScript code below, the file open function works as expected. However, when warnBeforeNew is true, an error occurs stating "Uncaught TypeError: Cannot read property 'root' of undefined". ...

v-for triggers actions on every div

Yesterday I posed a question regarding the removal of a custom truncate filter in Vue. If you missed it, you can find the original question here: Deleting a Vue custom filter when mousing over However, what I failed to mention is that I am utilizing a v- ...

The operation of my NodeJS application suddenly halts

In my project, I have a Server.js file that I run from the command line using: node server Within the Server.js file, a new instance of class A is created Class A then creates instances of both class B (web socket) and class C (REST API) If the web socket ...

What could be the reason for the malfunction of my personalized validation function?

Struggling with incorporating custom validation functions in Sails models. Everything runs smoothly without the custom function. However, once I add the function, everything comes to a halt. No data is saved to the database, the callback isn't trigg ...

Issue encountered in Babel version 6 with the transform-es2015-classes plugin in loose mode, causing a SyntaxError when using async/await

After updating to the latest version of Babel v6, I encountered an issue with the transform-es2015-classes plugin in loose mode (https://github.com/bkonkle/babel-preset-es2015-loose/blob/master/index.js#L8) causing problems with async/await functions. Here ...

Struggling to resize my icon correctly using tailwindCSS and Next.js with TypeScript

I've hit a roadblock with an issue that's been driving me crazy. I attempted to follow a tutorial on tailwindcss with next.js from YouTube. The goal was to utilize the heroicon library to create a stylish header with an icon. However, the icon I& ...

What is the best way to incorporate two separate events in AngularJS for a DOM element based on whether the user is accessing the site

I am currently in the process of transitioning my application from relying on numerous jQuery Widgets to incorporating AngularJS. However, I am facing difficulties in finding an optimal solution for the following issue. There is an image that should displ ...

Decoding JSON in iOS using Swift

{"data":[33689822,64091979,69682048,74160161]} - - (void)fetchData:(ASIHTTPRequest *)request { NSString *responseString = [request responseString]; NSLog(@"Request successful: %@",responseString); SBJSON *parser = [[SBJSON alloc] init]; ...

swap out the CSS class for my own class dynamically

When I display HTML code like this <div class="btn btn-pagination"> <i class="fa fa-angle-right"></i> </div> and want to replace fa fa-angle-right with myClass when the page loads. I attempted: $(document).ready(function () { ...

An issue has occurred: Cannot access the properties of an undefined object (specifically 'controls')

I encountered an error message stating "TypeError: Cannot read property 'controls' of undefined" in the code that I am not familiar with. My goal is to identify the source of this error. Below is the HTML code snippet from my webpage: <div ...

Looking to implement a jQuery ajax request for footable v3 specifically for a webservice. How can I achieve this?

After reviewing the footable documentation, I noticed that they only provide a method for fetching data from a file, and not from a webservice. Despite trying various combinations to retrieve JSON-formatted data into the footable instance, I have had no su ...

Unclosed JSON object detected in jsonobject line 19

Hello, I am new to android development and currently working on a simple login application using Volley to get a JSON response from the server. Here is an example of the JSON response I am receiving: JSON Response: {"loginResult":"{\"UserLoginID&bso ...

Monitoring inbound and outbound traffic in express middleware

I am in the process of incorporating a logger into my Express application. This logger needs to record both requests and responses (including status codes and body content) for each request made. My initial approach involves creating a middleware function ...

Issue with TinyMCE Editor: Inoperative

<script type="text/javascript" src="<your installation path>/tinymce/tinymce.min.js"></script> <script type="text/javascript"> tinymce.init({ selector: "textarea", theme: "modern", plugins: [ "advlist autolink li ...

Can an ajax call trigger the renewal of an ASP.NET session?

Currently tackling a timeout detection issue in an asp.net project. I've implemented an ajax function that checks every 5 seconds to determine if the session has expired. Interestingly, without the ajax function running, the session actually times out ...

After clearing the option, the onChange function stops functioning

I'm facing an issue with the following code: success: function (data) { $('#' + idDivRefresh).endLoading(); if (data.message != '@Geral.Sucesso') { $('#' + idDropDown + ...

Creating a specific type of table using Ruby on Rails

Is it feasible to create a table with two columns, where the left column incorporates multiple rows with a scroll bar, and the right column contains a large box housing buttons that alter based on the selection of blocks in the left column? ...

Utilizing a class function within the static method `getDerivatedPropsFromState`

I've been updating the deprecated life-cycle method componentWillRecieveProps() to its new replacement static getDerivatedPropsFromState(). The issue I'm encountering with this update is that componentWillRecieveProps() uses a class function int ...