Refresh an AngularJS table built with Bootstrap to display live data in real-time through the use of ng-repeat

Utilizing a bootstrap table with ng-repeat to populate data, yet encountering issues updating and displaying the table.

A custom directive has been created for drag and drop functionality in AngularJS. When a file is dragged and dropped, the information is successfully retrieved in the controller.

The issue lies in updating the table dynamically with the file details obtained.

 $scope.getFiles = function(res)
     {
        $scope.fileList = res;
        console.log(res);
     }

Within the HTML:

<file-drop fetch-files="getFiles"></file-drop>

The 'getFiles' function is called in the controller and returns the value. Despite seeing an object in the console through 'console.log' during drag and drop actions.

However, when assigning the data:

$scope.fileList = res;

In the HTML:

<table  class="table table-condensed" >
 <thead>
      <tr>
        <th>Name</th>
        <th>Type</th>
        <th>Size</th> 
        <th>Last Modified</th>
      </tr>
  </thead>
  <tbody>
      <tr ng-repeat="file in fileList">
        <td>{{file.name}}</td>
        <td>{{file.type}}</td>
        <td>{{file.size}}</td>
        <td>{{file.lastModified}}</td>
      </tr>
   </tbody> 
</table>

Using ng-repeat in HTML does not display anything as expected. The values are pushed into an array within the directive, maintaining previous drop info until the browser is refreshed.

How can the table be updated in real-time? The object structure includes:

[{name: "Topic_modelling.xlsx", type: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", size: 39274, lastModified: Mon Aug 03 2015 13:40:53 GMT+0530 (IST)}]

Answer №1

When you replace the entire object, this issue occurs.

Angular is monitoring the previous object, which is overwritten by

$scope.fileList = res;

The simplest solution is to use the "controller as" syntax in controllers so that your object is treated as a property in the template.

https://docs.angularjs.org/api/ng/directive/ngController

Therefore, your controller would look like this:

... 
this.getFiles = function(res)
     {
        this.fileList = res;
        console.log(res);
     }

and the template:

<div ng-controller="NameOfController as fileCtrl"

...

<tr ng-repeat="file in fileCtrl.fileList">

After making these changes, Angular will watch the property of the fileCtrl object instead of the primitive value.

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

Having difficulty with Mongoose in MongoDB when trying to retrieve an array of strings that match existing collections in the database

I've designed a helper function that is supposed to generate a promise containing an array of strings that represent all the names of Collections currently stored in my database. After conducting console logs, I confirmed that my connection to the da ...

Manipulating links using JQuery: avoiding the binding of new links

I need to update a website with 50 pages that currently doesn't use ajax, making it cumbersome to make edits since changes have to be made on all 50 pages individually. After removing duplicate HTML from all 50 pages, I'm facing some issues: fu ...

Utilizing JSON in a d3.js application within a Rails environment

I have been exploring the gem gon in order to generate JSON data from my Rails database. I have successfully managed to display this data in an alert, but now I am looking to visualize it using d3.js. Within my database named "users" with columns (name:st ...

Error 400 encountered in Spring MVC with Ajax

I am working on a Java application using Spring MVC and encountering some issues with sending AJAX requests to a Spring controller. I have noticed that when I include the headers "Accept", "application/json" and "Content-Type", "application/json;charset=ut ...

JS/Docker - The attribute 'user' is not recognized in the context of 'Session & Partial<SessionData>'

I'm attempting to integrate express-session into my Node.js application running within Docker. I've come across several discussions on the topic: Express Session: Property 'signin' does not exist on type 'Session & Partial<Se ...

There are occasional instances in Angular 6 when gapi is not defined

I am currently developing an app with Angular 6 that allows users to log in using the Google API. Although everything is working smoothly, I encounter a problem at times when the 'client' library fails to load and displays an error stating gapi i ...

Looking to receive a JSON response using jQuery Ajax in Spring MVC? Check out the following Ajax code snippet I've written:

How can I receive a JSON response using jQuery Ajax in Spring Mvc? Below is the ajax code : $.ajax({ type: 'POST', url: "fetch", dataType: 'json', data: {clientidedit:client ...

Encountering an issue while attempting to replicate the Spotify app on localhost:3000. The error message "TYPEERROR: Cannot read property 'url' of undefined" is hind

As a first-time user of stackoverflow, I am unfamiliar with its rules and regulations, so I apologize in advance for any mistakes I may make. Currently, I am attempting to create a Spotify clone using React. Everything was going smoothly until I completed ...

Issue with Mat-AutoComplete arising while utilizing a formArray

After adding a form array to account for multiple rows, I had to modify my definition from: shoppingCartList Observable<any[]>; to shoppingCartList: Observable<any[]>[] = [];. However, this change resulted in an error in my filter function whic ...

Retrieve the concealed division element's HTML content along with its formatting

Help needed with appending a hidden div with its styles intact. Despite using the code provided below, the appended div does not retain its styles. Any suggestions for an alternative method? var warningMessage = $('#warningDiv').html() fun ...

Having trouble with the updateOne() method in MongoDB - it's not updating my document nor displaying any errors. What could be the issue?

I'm currently facing an issue where I am attempting to update a user's document in the database with a value obtained from a calculator. However, despite not encountering any errors, the document does not seem to be updating and the page just con ...

Creating a Union Type from a JavaScript Map in Typescript

I am struggling to create a union type based on the keys of a Map. Below is a simple example illustrating what I am attempting to achieve: const myMap = new Map ([ ['one', <IconOne/>], ['two', <IconTwo/>], ['three ...

How can I retrieve the updated input value once a specific key has been pressed in the prototype?

After a customer presses any key, I would like to check an email. Below is the code I am using: document.observe("dom:loaded", function() { $('billing:email').observe('keypress', function(event){ console.log(event.element(). ...

Exclude a variety of keys using wildcards or regex when conducting comparisons

How can I exclude certain properties in a JSON object that contain specific characters? var obj1 = {name: "James", age: 17, creation: "13-02-2016", deletion: "13-04-2016", foo_x:"", foo_y:"", foo_z:""} var obj2 = {name: "Maria", age: 17, creation: "13-02- ...

Switch up the Javascript popup code without any specific pattern

I am looking to add variety to my pop up ads on my website by randomly changing the Javascript code for each ad every time a page is loaded. How can I achieve this? Script 1 <script type="text/javascript"> var uid = '12946'; var w ...

The Node.js promise failure can be unpredictable, despite being properly managed

In my journey to master MongoDB, I am currently exploring its capabilities by building a basic blog application. However, I have encountered an issue with the code responsible for saving blog posts - it seems to be inconsistent in its success rate, sometim ...

Create a properly formatted JSON object from a PostgreSQL query

I'm working with a Postgresql table that has the following structure: ID CURRENCY PRICE 1 EUR 100 2 USD 90 My goal is to create a query that will return a JSON object formatted like this: { "EUR": 100, "USD ...

How to efficiently transfer data between Node and Angular 7 using Electron

After setting up an Angular 7 application running on http://localhost:4200, I developed a Node JS application responsible for authenticating users on Facebook, accessible at http://localhost:3000. The callback redirection functions correctly within the No ...

Is it possible to pass an HTML element's id attribute to a function in JavaScript?

In the following code snippet, I am looking to send the id=content to the function mr and then display the result in the passed id=result. While this functionality is currently limited to this HTML file, I aim to extend it to other HTML pages by adding the ...

JavaScript file encountering a problem with its global variables

What is causing the alert("2") to pop up first instead of it being second? Why am I encountering difficulty creating global variables c and ctx? Is there a way for me to successfully create these two global variables in order to utilize ...