Repeating single records multiple times in AngularJS with ng-repeat

I've been working on a project using AngularJS and have encountered some strange behavior with ng-repeat. My controller is returning data to ng-repeat as follows:

.....
//Other JS Functions
.....
var app = angular.module('main', ['ngTable']).
        controller('DemoCtrl', function($scope, ngTableParams) {
            var data = [
                //data in JSON form
            ];

            $scope.tableParams = new ngTableParams({
                page: 1,           
                count: 5           
            }, {
                total:data.length,
                getData: function($defer, params) {
                    var slicedData = data.slice((params.page() - 1) * params.count(), params.page() * params.count());
                    alert(slicedData.length);
                    console.log(slicedData);
                    $defer.resolve(slicedData);
                }
            });
        })

Everything seems fine up to this point as I am receiving the expected data after slicing it.

However, when I use ng-repeat to display the data in tables like so:

<table ng-table="tableParams" class="table ng-table-responsive">            

            <tr ng-repeat="d in $data">

                <td data-title="Name">
                    {{d.id}}
                </td>
                <td data-title="Length">{{$data.length}}</td>
                <td data-title="Age">
                    {{d.ciscoID}}
                </td>
            </tr>
 </table>

The issue arises where although the length displayed is accurate at 5, each record is shown multiple times (e.g. 25 if count is set to 5). Even if I change the count to 10, each record will be repeated ten times.

I find this perplexing since:

<td data-title="Length">{{$data.length}}</td>

correctly displays the length of the data array. So, I would expect the iteration to be correct as well.

Furthermore, I've noticed that my getData() method in the controller is being called twice for some reason. Any insights or guidance on this matter would be greatly appreciated. Thank you :-)

Answer №1

Solving the problem was as simple as updating the 'JS' and 'CSS' files to their most recent versions.

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

issues with the functionality of bootstrap modal

I'm currently working on a project where I need to set up a modal popup using bootstrap. The website I'm working on is organized by departments, so the only part of the code that I have control over is the main body of the site. I have included t ...

Angular's observable function is not providing a complete response

In my Angular component, I have a function that is called from a template. This function returns an Observable of type string, but unfortunately it only returns the `data` variable. How can I modify it to return `dateNew[0] + " de " + data + " de "+ dateNe ...

Struggling to retrieve a JSON object from an Express and Node application, only receiving an empty result

Can anyone assist me? I'm having trouble with the res.json() function in my code. It seems to work after the first request, but not after the second. Right now, my application is quite simple - it scrapes user data from social media platforms like Twi ...

Objects and strings cannot be inserted into a JavaScript array

For hours, I've been attempting to troubleshoot this code. Currently, it successfully finds the number of anchors, and I have an array that is of undetermined size. Within the for loop, it retrieves the anchor and extracts the .href. I've confirm ...

The error message displayed reads as follows: "topojson has encountered a TypeError: Unable to access the property 'feature' as

Context A problem has arisen with JavaScript when trying to use the topojson.feature(topology, object) function. It seems that this issue appeared after moving from TopoJSON version 1.6.26 to version 2.x, although the functionality remains similar. The p ...

Controlling the HTML5 dialog element within a React application

Struggling to implement a basic configuration dialog with a close icon in the top-right corner using React. In other frameworks, it's easy to show/hide a dialog with .showModal()/close(), but manipulating the DOM directly in React is not recommended. ...

Uncovering the websocket URL with NestJS and conducting postman tests: A step-by-step guide

Creating a mean stack application using NestJS involves utilizing websockets. However, testing websockets in Postman can be confusing. Typically, I test route URLs in Postman and get output like: "http://localhost:3000/{routeUrl}". But when it comes to tes ...

Refreshing the state of the redux reducer

I am encountering an issue with updating content on the same page. Despite making changes to the data, it continues to display old information after a server update. The name currently displayed is Arnold Schwarzenegger. Even after successfully updating ...

Fetching a destination through the post approach

Typically, we utilize window.location.href="/index.php?querystring"; in JavaScript. Is it possible to transmit the querystring via a POST method without including any form within the document? ...

Is there a more efficient method to avoid selecting the same option in an md-select menu?

When working with the Angular Material md-select control, my scenario requires displaying a warning message to the user whenever they change the options from the dropdown. This serves as a reminder that the currently visible data may not match the selected ...

Tips for effectively monitoring scope for data loading

I have successfully created a custom Angular directive that utilizes D3.js to create a visualization. In my HTML, I reference this directive as follows: <gm-link-analysis data="linkAnalysis.connections"></gm-link-analysis> The relevant part o ...

Exploring methods to trace the factory's property that is receiving updates from another factory within AngularJS

Hey there, I'm new to Angularjs and I have a bunch of factories in my application. The situation is, let's say we have obj1 in factoryA. Whenever I console.log(obj1), it displays numerous properties associated with it. This object is being update ...

Transferring data to modal scope using angular ui-bootstrap

I am currently working on an Angular form that utilizes a ui-bootstrap modal dialog in my Sharepoint site. The site has different language versions, English and Spanish, and I need to display the appropriate content based on the context. My challenge is ...

The traditional function does not have access to a reference to this

For my web development project with Angular 9, I needed to add a typeahead feature using ng bootstrap typeahead. The code provided below worked perfectly: search = (text$: Observable<string>) => text$.pipe( debounceTime(150), disti ...

Is it possible to adjust the size variable in Angular controllers/services using Bootstrap?

Is there a way to dynamically adjust functionality in Angular services/controllers based on the current Bootstrap3 breakpoint (xs, sm, md, lg)? For example, opening a Kendo-UI window on desktop, but using a simple 100% width window on mobile. I'm loo ...

Retrieving a property of an object within a function

I'm facing an issue where I am trying to access the properties of objects inside an array in my code to display text values in input boxes that are recovered from local storage after a refresh. However, when I attempt to run a for loop within my appSt ...

"electron-builder - initially designated for building app for Mac only, but now configured to build for both Mac

This is my first attempt at creating an electronjs app, so I may not have a full grasp on what I'm doing. I've been following the instructions on GitHub and also this guide from Medium. Here's a snippet of my package.json: { (package.jso ...

Use include files to wrap content in a div tag

I have a webpage index.html with the following JavaScript scripts: <script type="text/javascript> $(document).ready(function() { $('a.link').click(function() {var url = $(this).attr('href'); $('#content'). ...

Firebase Cloud Function variables causing 'unidentified' output

While experimenting with firebase cloud functions, I'm encountering an issue with a constant error message stating that userID is undefined. It's preventing the function from running smoothly. https://i.sstatic.net/MsnsV.png Below is the databa ...

I'm fascinated by the way well-known websites like The Guardian are utilizing Angular, as I often notice that when I click on links, the entire page reloads

As a beginner in Angular, I recently explored popular websites that implement Angular or React. I discovered sites like The Guardian, New York Times, and Netflix. However, most of these sites have links that open in new pages, while the remaining ones ut ...