Trouble displaying items from an Array using ng-repeat directive in AngularJS

Recently, I started learning AngularJS and encountered an issue with displaying objects from an array in my view.

This is the snippet of JavaScript code that I have:

// Initializing list:
vm.latestInvoices = { invoices: []};
....

// Adding function to viewmodel:
vm.getLatestInvoices = getLatestInvoices;
...

    function getLatestInvoices() {
        console.log("Test 1234");
        var servicename = "GetLatestInvoicesRequest";

        var params = {};

        httpCall(servicename, params).then(function (data) {
            vm.latestInvoices = data;
            console.log(data);
            return vm.latestInvoices;
        })["catch"](function (data) {
            console.log("getLatestInvoices error");
        });
    }

Here's the snippet of HTML view:

<div class="col-lg-12">
        <p id="overview-headline">Invoices Overview</p>
        <div class="scrollCustomers" ng-init="vm.getLatestInvoices()">
            <table class="table table-hover">
                <thead>
                    <tr>
                        <th>Client</th>
                        <th>Project</th>
                        <th>ID</th>
                        <th>Inv. Date</th>
                        <th>Start Date</th>
                        <th>End Date</th>
                        <th>DKK ex VAT</th>
                        <th>CIG</th>
                        <th>Attention</th>
                        <th>Cust. Manager</th>
                        <th>Regarding</th>
                        <th>Due Date</th>
                        <th>Finalized</th>
                        <th>Paid</th>
                    </tr>
                </thead>
                <tbody>
                    <tr ng-repeat="invoice in invoices">
                        <td>{{invoice.CompanyName}}</td>
                        <td>Project Name</td>
                        <td></td>
                        <td></td>
                        <td></td>
                        <td></td>
                        <td></td>
                        <td>Default</td>
                        <td></td>
                        <td></td>
                        <td></td>
                        <td>N/A</td>
                        <td>N/A</td>
                        <td>N/A</td>
                    </tr>
                </tbody>
            </table>
        </div>
    </div>

Although the Google Dev console displays the array and its objects correctly, the view doesn't show the default values for Project Name, Default, and N/A. It seems like the ng-repeat for invoices is not being called for some reason.

Thank you for your help!

Answer №1

Add the outcome to the $scope:

makeHttpCall(service, parameters).then(function (result) {
        vm.latestRecords = result;
        console.log(result);
        $scope.records = result;
    })["catch"](function (error) {
        console.log("Encountered an error fetching latest records");
    });
}

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

Toggle visibility between 2 distinct Angular components

In my application, I have a Parent component that contains two different child components: inquiryForm and inquiryResponse. In certain situations, I need to toggle the visibility of these components based on specific conditions: If a user clicks the subm ...

Replicate the ctrl+/- function through coding

While browsing with your browser, you have the ability to adjust the font size by using CTRL + + or CTRL + -. Is there a way to replicate this functionality through code, such as with JavaScript? I am looking to add buttons on my website that allow users ...

Creating a unique aspect ratio for your div with CSS

This is my current design. https://i.sstatic.net/VOexn.png This is the layout I aim to achieve: https://i.sstatic.net/hMy7C.png 1. The width and height of the outer container should maintain the specified aspect ratio. 2. The content area should als ...

How come I am unable to scroll beyond my parallax section unless I move the mouse first?

Currently, I am working on a webpage that includes a Parallax landing image. In order for the Parallax effect to function properly, the image has a greater height, requiring users to scroll down. This leads to the appearance of a second scrollbar specifica ...

"Click events on jQuery's cloned elements are not retained when the elements are removed and appended to a container for the second time

Take a look at this fiddle: https://jsfiddle.net/L6poures/ item.click(function() { alert("It's functioning") }) $("#container").append(item) var stored = item.clone(true, true) function add_remove() { $("#container").html("") $("#conta ...

Retrieve numerous rows from MSSQL database and separate into individual arrays for each row

I am facing a challenge with my MSSQL query. It fetches all rows that meet specific criteria, and I want to convert the fetched array into one unique array per row using PHP. For instance, if the query returns 3 rows, I aim to have 3 distinct arrays for fu ...

Setting up web pack with flag-icon-css integration

I have successfully set up a webpack project using https://github.com/teroauralinna/webpack-guide. Now, I am looking to integrate https://github.com/lipis/flag-icon-css into my project. To do so, I followed these steps: npm install flag-icon-css --save T ...

Utilize a select box to toggle between enabling and disabling options

Could someone please help me with enabling and disabling a text field based on a select box option? I'm not sure if I have written the code correctly below. If there are any errors, please correct me. <body> <table width="500" border="1"> ...

Utilizing the Bootstrap Carousel tied to a specific slide index

Here is a simple HTML page I have created. <html> <head> <link rel="stylesheet" href="style.css"> <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css&quo ...

Conceal or reveal buttons using JavaScript

I am struggling with a function that is supposed to hide certain buttons and create a new button. When I click on the newly created button, it should make the previously hidden buttons visible again. However, the function does not seem to work properly. ...

Adjust the color of the stacked bar graph

I am looking to customize the color of individual bars in a stacked bar chart based on two different categories: APP Used and APP not used. Specifically, I want APP Used bars to be green and APP not used bars to be red, instead of the default black and gre ...

Update the background image every minute with a smooth transition effect

I am currently in the process of developing a personal dashboard that requires dynamic background images to change every minute. To achieve this functionality, I have integrated the [Pixabay API][1] and formulated the following API request: https://pixaba ...

Begin running the following function once the prior asynchronous function has completed its execution

I'm currently working on a route to save real estate listings back to the MongoDB database. The challenge I'm facing is with uploading an array of up to 10 base64 images to Cloudinary. Each image undergoes asynchronous upload, and I need all the ...

Access data from two collections in mongoDB by utilizing the limit and skip functions

I am dealing with two collections named "Order" and "Production Order". With a record limit of 40 per page, I aim to display a total of 40 records from both collections. Here are my queries: 1) Is it possible to retrieve records for both collections using ...

React App searching for unused static files

Currently, my React application is deployed on the Nginx web server. Accessing the application using the URL XX.XX.XX.XX works fine. However, I want to be able to access it through the URL XX.XX.XX.XX/myapp/frontend. To achieve this, I have set up a revers ...

The issue with Angular's ng-click directive failing to function properly in Internet Explorer 11

I'm facing a strange issue with a basic ng-click function that is functioning properly in all browsers except for IE10 and 11 (I haven't had a chance to test it on Edge yet). Below is the directive I am using: $scope.showMoreDetails = false; ...

Using javascript to overlay and position many images over another image

I've searched extensively but haven't been able to find any relevant answers here. Currently, I am developing a hockey scoring chance tracker. My goal is to display an image of the hockey ice where users can click to mark their input. Each click ...

Transforming a relation by breaking down an array to output one row for each entry in the array

If we have a table defined as shown below: CREATE TABLE test_values(name TEXT, values INTEGER[]); ...with the following values provided: | name | values | +-------+---------+ | hello | {1,2,3} | | world | {4,5,6} | The goal is to create a query that wi ...

Holding off on triggering a jQuery Ajax request until a function returns a value

I'm currently facing an issue where an Ajax request is not waiting for a function call to return before executing. The specific scenario involves calling getSelectedMessages to retrieve checkbox values and then passing these values in an array to the ...

Differences in behavior of Backbone.js Ajax calls between Chrome and Firefox

I am encountering an unusual problem in Firefox. When we load a page and call Routers.initializeRouters(); an ajax request is sent to fetch the data, and the loadFormSuccessHandler function populates the response into the views. In Chrome, the Ajax reques ...