What is the best way to showcase the information retrieved from my API?

I am attempting to display the ID and Document number that are retrieved from an array.

Data Returned

However, I am not seeing any results in return. You can view the application results here.

I have tried using string interpolation like {{document.id}} and {{document.documentNumber}}, with the interface setup as id: string and documentNumber: string. Below is my HTML code:

<div class="grid-container">
  <div class="grid-item" *ngFor="let document of documents">
    <div>Document ID: {{ document.id }}</div>
    <div>Document Number: {{ document.documentNumber }}</div>
  </div>
</div>

This is the GET method information:


   public getDocuments(): Observable<Documents[]> {
        let url = this.config.url;
        if (!url.endsWith("/")) {
            url += "/";
        }
        console.log("getDocument URL:", `${url}api/v1/document/`);
        return this.http
            .get<Documents[]>(`${url}api/v1/document/`, {
                headers: {
                    authorization: this.config.authorization,
                },
            })
            .pipe(
                map((data) => {
                    console.log("getDocument:", data);
                    return data;
                }),
                catchError((error) => {
                    console.log("getDocuments Error:", error);
                    throw error;
                })
            );
    }

Here is the component information:

export class DocumentListComponent implements OnInit {
    public documents: Documents[] = [];

    public constructor(private aService: AService) {
        console.log("DocumentListComponent constructor", aService);
    }

    public ngOnInit(): void {
        console.log("DocumentListComponent ngOnInit");
        this.aService.getDocuments().subscribe((documents: Documents[]) => {
            console.log("Received Documents:", documents);
            this.documents = documents;
            console.log("DocumentListComponent ngOnInit", this.documents);
        });
    }
}

Answer №1

You may want to retrieve data from document.document.id and document.document.documentNumber, since they are nested within each array item under the document object.

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

Obtaining only string values when looping through JSON information

JSON: { "status": "success", "data": { "9": { "1695056": { "id": "1695056", [...] }, "csevents": { "2807": { "id": "280 ...

Issues with implementing Dark mode in TailwindCSS with Nuxt.js

After spending a couple of days on this, I'm still struggling to get the dark mode working with Tailwind CSS in Nuxt.js. It seems like there might be an issue with the CSS setup rather than the TypeScript side, especially since I have a toggle that sw ...

What is the most effective method for importing the "exceljs" library into an Angular project?

In my Angular 7 app, I am utilizing exceljs (https://www.npmjs.com/package/exceljs) to handle importing and exporting of Excel files. Currently, I have imported it using the following code snippet: import {Workbook} from "exceljs";. While it functions perf ...

Code snippet in Java to divide a JSON string into separate lines based on specific symbols

In my app, I need to generate a JSON text file with a specific structure: { "key1" : "value1" , "key2" : "value2" , "arrayKey" : [ { "keyA" : "valueA" , "keyB" : "valueB" , "keyC" : [ 0 , 1 , 2 ] } ] } This data needs to be formatted from JSONObject.toS ...

What is the best way to resolve the "unknown" type using AxiosError?

I'm currently working on developing a customized hook for axios, but I've encountered the following error: Argument of type 'unknown' is not assignable to parameter of type 'SetStateAction<AxiosError<unknown, any> | unde ...

Customize the columns of your Angular Material 2 table by defining them using TemplateRef and ngTemplateOutlet

Looking to create a flexible material table with the ability to utilize TemplateRef along with ngTemplateOutlet for generating columns. Check out this demo where I have employed the cards component within my custom material-table component. Inside the card ...

Having trouble fetching data from a connected Android device to a localhost endpoint using React-Native

I am relatively new to React Native and I am currently working on developing an application. I have a JSON post request that functions correctly on Postman and Expo when accessed through a web browser at http://127.0.0.1:8080. However, when attempting to r ...

I am interested in utilizing the request-reply pattern with KafkaJS in a TypeScript environment. Could you provide guidance on how to successfully implement this?

I am new to Kafka and I am trying to implement the request-reply pattern using kafkajs in TypeScript. However, my current implementation is very basic and the consumers inside producers are taking too long to start, causing delays. Is there a better way to ...

The variables declared within the Promise constructor are being identified as undefined by Typescript

In my code, I am creating a let variable named resolver which I intend to set within a promise constructor function. interface Request { ids: string[]; resolver: () => void; promise: Promise<unknown> } class Foo { public requests: ...

What is the best way to add JSON data received from an AJAX response to multiple classes?

Currently, I am honing my skills in jquery and have hit a bump in the road. I am receiving JSON data from a fantasy football API and am trying to map over the data to assign each team owner and name to their own div. My main query revolves around how I can ...

My bootstrap collapse navbar isn't functioning properly. Despite pressing the icon on a smaller screen, the menu fails to open. Can anyone provide a solution to this issue?

The hamburger menu is not working properly. I am facing an issue where the navigation does not appear when I press on the hamburger icon on a small screen. Can someone please guide me on how to resolve this problem? :/ <nav class="navbar bg-d ...

What is the best way to access and verify data from an array that has been passed through props

I am working with a component that takes an array as a prop <Component runners={['1','2']}/> Inside this functional component, my goal is to generate an element for each value in the array. Here's my logic: const { runners ...

Validating Floating Point Numbers in C++

Hey there, I have a float array that only stores 1s and 0s. I'm attempting to run a simple test where if the current index in the array is 1, it will display a message saying it is 1, otherwise it will say it's 0. Here's my code snippet: if ...

Solving the "ExpressionChangedAfterItHasBeenCheckedError" in Ionic: A Guide

//html <span style="margin-left:43%;background-color:rgb(229,229,229);border- radius:10%">&nbsp;&nbsp;{{formatEpoch(epoch)}}&nbsp;&nbsp;</span> //ts lastdate:any; formatEpoch(epoch): string { ...

What is the reason for storing a base64 string as an Object in a MongoDB database?

I am facing an issue with storing a product detail on the mongoDB database. When I try to save it, mongoDB stores a property imageSrc as an object instead of a string. Here is my database This is my angular service And this is my express server request ...

Guide to iterating through a JSON object

Initially, I expected a simple question but it's proving to be more challenging than I thought. To provide some context, there is a JSON string returned from the server located within data.occupation. {"occupation": "Boxer", "id": 2},{"occupation": " ...

Blip Scripts: Converting JSON to JavaScript - Dealing with Undefined Arrays

I am currently working on a project to develop a bot on Blip. There are certain parts where I need to send a request to an API and then use a JavaScript script to extract elements from the JSON response. The JSON response I received from the API is stored ...

VSCode on Mac is closing the terminal without any warning or delay

Recently, I updated my MacOS to Ventura 13.0.1 and encountered a problem with my VScode. Every time I run the code, the terminal opens and closes immediately without displaying anything. Below are my settings.json: { { "window.zoomLevel&q ...

The reason behind the clickable issue with my duplicate <ion-select>

I've been working on a form using HTML, CSS, and JavaScript where I implemented an "Add" button to duplicate the form. The issue arises with the ion-select element within the duplicated form. While the original form displays all predefined options upo ...

Angular Link Panel

I'm working on a marketplace app and I need to display a picture and name of a product when someone shares a link. Similar to how social media posts include a picture and title when shared. Can this be achieved using Angular, and if so, what steps do ...