The data retrieved by the rest API is failing to display properly on the webpage

I'm having trouble fetching data from my custom REST API. The API is returning data, but Angular isn't loading it properly. I can see the data being passed in the network tab of the developer tools.

Here's the HTML code:

<!DOCTYPE html>
<html>
<head>
    <title></title>
    <meta charset="utf-8" />
    <link href="Content/bootstrap.css" rel="stylesheet" />
    <script src="Scripts/angular.js"></script>
    <script src="Scripts/angular-resource.js"></script>
</head>
<body ng-app="productsApp">
    <div ng-controller="productsController">

            <table>
                <tr ng-repeat="p in products">
                    <td>{{p.productName}}</td>
                    <td>{{p.productCode}}</td>
                    <td>{{p.releaseDate | date}}</td>
                    <td>{{p.price | currency}}</td>
                </tr>
            </table>
    </div>
    <script src="Scripts/App.js"></script>
    <script src="Scripts/http.js"></script>
    <script src="Scripts/service.js"></script>
</body>
</html>

This is the Service.js file:

(function () {
    angular.module("productService", ["ngResource"]).
    factory("product", function ($resource) {
        return $resource('http://localhost:55755/api/products/:id');
    });
}());

And here's the App.js file:

var app = angular.module("productsApp", ["productService"]);

app.controller("productsController", function ($scope, product) {

    $scope.products = product.query();
});

Answer №1

When using the query() method, you can handle the promise by injecting a callback function to be executed automatically within the promised part.

product.query(function (items) {
   $scope.items = items;
});

>> Check out the demo on JSFiddle

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

Setting up SSL Certificate for ASP.Net Core WebListener

With the release of ASP.Net Core, it's time to address a pressing issue for my web application. Due to a business requirement for self-hosting and NTLM authentication for Windows IDs, I need to use a WebListener server which requires an SSL Certifica ...

Is it possible to simultaneously employ two asynchronous functions while handling two separate .json files?

Is it possible to work with 2 .json files simultaneously? My attempt did not succeed, so I am looking for an alternative method. If you have a suggestion or know the correct syntax to make this work, please share. And most importantly, does the second .j ...

Eliminating an ngRepeat item from the $rootScope array does not automatically result in the item being removed from the html code

Attempting to eliminate an li from a ul using angular. Although the element is successfully removed from the array, AngularJS does not remove the li until it is interacted with, such as being hovered over or clicked. See the code below: app.js myApp.run( ...

The ID update functionality in Node.js is malfunctioning

Hello everyone, I am currently venturing into the world of NodeJS with a goal to create a backend API for a car rental agency. After writing some code to update, view, and delete records by id stored in MongoDB, I encountered a strange issue where it only ...

Launching ASP.NET MVC 4 Web API into Action

Issue with Deploying ASP.NET MVC 4 Web API I am facing a problem while deploying an ASP.NET MVC 4 Web API site. Everything seems to be working fine locally, but when accessing the server from outside and receiving HTTP status codes of 400 or higher, the W ...

Passing data through the @Input() directive

One issue I am facing involves passing data to a component using the @Input() decorator. The problem arises when I have a component called list that contains some data. Upon clicking the edit or view button, it loads another component. In my detailComponen ...

Is there a way to access the 'created by' and 'updated by' fields in StrapiJS?

Recently diving into StrapiJS has been a rewarding experience overall, but a new challenge has presented itself. Upon inserting data into the database, I noticed that Strapi automatically generates certain fields like created_by and updated_by, yet these ...

Issues with validating the input in the form

Having trouble getting the unique user name check to work while using the jQuery valid8 plugin to validate a register form. Here is the code for Register.php <?php include ("db.php"); ?> <script src='js/jquery-1.4.2.min.js' type=' ...

Comparing response times between AngularJS $http and $.ajax callbacks

I am puzzled as to why AngularJS $http service's success callback is giving me a slower response time compared to the $.ajax success callback. I ran this code 5 times with different JSON files: if(isJquery){ $.ajax({ type : 'GET', ...

The Facebook user interface dialog is altering the link once it has been sent

I am currently facing an issue with sending invitations via the Facebook Graph API. Each time I include an invitation code in the link and send it using the Facebook UI dialog, the link gets altered. FB.init({ appId: 'facebook_app_id', statu ...

Leverage the DistributedRedisCache within the OnTokenValidated Event of the JWTBearerOptions in ASP .Net Core

Running an ASP .Net Core API Project where JWTBearer Authentication and AddDistributedRedisCache are utilized. The goal is to blacklist tokens for immediate effect, such as in cases of admin user rights removal or logout. This ensures that a user must log ...

Recording transmitted information during an ajax call

I have the following code snippet $.ajax({ type: 'POST', url: '', contentType: 'application/json; charset=utf-8', data: { Name: name, TableData: tableData }, dataType: 'json' }); This includes a ...

Angular 14 debug error: Incorrect base path setting

Whenever I go for a run, I have to specify a starting point such as /pis/ ng serve --serve-path /pis/ Even after following these instructions, nothing seems to load. Can anyone lend a hand with setting a starting point in the ng serve process? ...

Stop the window from scrolling up smoothly when opening a custom modal to avoid any flickering

I encountered a problem with a custom modal window that would open on click and move to the top of the viewport. The issue was that when scrolling up, the page beneath would be visible, so I needed to restrict scrolling once the modal was open. Below is th ...

Generating an error state in AngularJS

At a factory in my app, there is a particular piece of code that handles uploading and saving: upload_and_save: function(model){ var personalInfoUpdated = $q.defer(); if (typeof(model.image) === 'object') { ...

When using Javascript to include a selection in an HTML drop-down menu, no changes occur

No matter how many code examples I copy from various sources, my attempts to add options to an HTML drop down list have been unsuccessful. Here is the script that I am working with: <!DOCTYPE html> <html><head></head> <body> & ...

A Preload Link was discovered for Google Adsense, yet the browser failed to utilize it

Operating my Wordpress website [followmyinstagram.de] with Google Adsense implemented directly into the theme's code. No plugins are used for Adsense integration. Upon analyzing the page speed, Chrome displays a warning that a preload link for "" is ...

Moving the HTML object back can be achieved by translating several times on the X axis followed by translating on the Y axis

Before I proceed with my inquiry, please keep in mind the following: I have no intention of using a game engine. This game is being created using HTML, CSS, and JavaScript. The controls are set to three arrow keys, where clicking on one should move in th ...

Guide on implementing ng-change in a select dropdown for dynamically populating data

As a newcomer to AngularJS, I am currently working on an Ionic app where I am facing an issue with populating select options based on the selection of the first option. The variable selected in the first select option is not being processed correctly to re ...

Utilize an iframe input field to initiate a Jquery event

Thanks to this amazing platform, I was able to discover a solution for expanding an iframe upon clicking using HTML and Jquery. However, my issue remains unresolved. I have successfully expanded the iframe with text, but I want to use input fields within ...