Data missing from nested interface post-mapping

Utilizing HttpClient in Angular, I am retrieving data and using an interface to map the nested JSON response, but encountering missing values in one of the nested arrays.

Component:

export class PlansDetailComponent implements OnInit {
  exerciseForm: FormGroup = new FormGroup({})
  planId? : number;
  plan? : Plan;

  constructor(private route: ActivatedRoute, private http: HttpClient, private formBuilder: FormBuilder) { }

  ngOnInit(): void {
    this.route.paramMap.subscribe(params => {
      this.planId = Number(params.get('id'));
    });
    this.http.get<GetPlanQueryResult>('https://localhost:7186/plans/'+this.planId).subscribe({
      next: response => {
        this.plan = response.plan
        console.log(this.plan.exercises[0].records);
        this.initializeForm();
      },
      error: (err) => {
        console.error(err);
      }
    })
  }

Interfaces created for mapping data:

import {Plan} from "./plan";

export interface GetPlanQueryResult {
  plan: Plan;
}
import {Exercise} from "./exercise";

export interface Plan {
  id: number;
  archived: boolean;
  name: string;
  exercises: Exercise[];
}
import {Record} from "./record";

export interface Exercise {
  id: number;
  name: string;
  description: string;
  records: Record[];
}
export interface Record {
  weight: number;
  repetitions: number;
  date : string;
}

A sample JSON response obtained from Postman:

{
    "plan": {
        "id": 1023,
        "archived": false,
        "name": "testssss",
        "exercises": [
            {
                "id": 1044,
                "name": "klata",
                "description": "",
                "records": [
                    {
                        "weight": 2,
                        "repetitions": 0,
                        "date": "2024-07-09T00:00:00"
                    },
                    {
                        "weight": 2,
                        "repetitions": 0,
                        "date": "2024-07-09T00:00:00"
                    }
                ]
            },
            {
                "id": 1045,
                "name": "klata",
                "description": "",
                "records": [
                    {
                        "weight": 3,
                        "repetitions": 0,
                        "date": "2024-07-09T00:00:00"
                    },
                    {
                        "weight": 3,
                        "repetitions": 0,
                        "date": "2024-07-09T00:00:00"
                    }
                ]
            }
        ]
    }
}

The API returns records, but after mapping, the records array appears empty.

https://i.sstatic.net/QjuKiVnZ.png

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

Filtering an array dynamically in Typescript depending on the entered value

My task involves filtering arrays of objects based on input field values. Data data: [{ taskname: 'Test1', taskId: '1', status: 'Submitted' }, { taskname: 'Test2', taskId: '2', status: 'Re ...

Custom type checker that validates whether all properties of a generic object are not null or undefined

In an attempt to create a user-defined type guard function for a specific use-case, I am faced with a challenge: There are over 100 TypeScript functions, each requiring an options object. These functions utilize only certain properties from the object wh ...

Ng5 npm is encountering an error stating 'Module './topologicalSort' could not be located.'

I encountered an issue with my Angular 5 app. Whenever I attempt to run it, I receive the following error message after running an npm start. Error: Cannot find module './topologicalSort' I suspect that this issue is related to 'webpac ...

Is it possible to utilize Angular Routing when converting a single page application to display two routes simultaneously with a split view?

I am currently working on an application built using the VS2017 Angular template, which is a single page app with 3 defined routes in app.module.ts. RouterModule.forRoot([ { path: '', component: HomeComponent, pathMatch: 'full' }, ...

Is it necessary to have a premium firebase/firestore account in order to set up stripe payments?

When learning how to integrate Stripe payments with Angular and Firebase, make note that a paid Firebase account is required for the cloud function to work. External API requests are blocked on the free "Spark" plan. ...

Reading text files line by line in TypeScript using Angular framework is a valuable skill to have

Struggling with reading text files line by line? While console.log(file) may work, it doesn't allow for processing each individual line. Here's my approach: In api.service.ts, I've implemented a function to fetch the file from the server: ...

Communicating between different components in Angular 11 using a service to share data

In my Angular 11 project, componentB has multiple methods that need to be called from componentA. Although I am aware that transferring these methods to a service would be the proper solution, it requires extensive effort which I want to avoid for now. In ...

Enhance autocomplete functionality by incorporating a left icon feature for text fields within the autocomplete component

I have a component with autocomplete functionality that displays tags Autocomplete with tags and I am trying to add a left icon, but only the right icon is functioning correctly. Current Issue When I add a left icon, it shows up but prevents the renderi ...

How to perform a fetch on a local path in Next.js?

Is there a way to use the fetch method with a relative path like this: export async function getServerSideProps() { // Fetch data from local API const res = await fetch(`/api/get_all_prices`) const data = await res.json() // Pass data to th ...

The FormData object is unrecognized / axios / jest

I encountered an issue while testing my axios based service where Jest is throwing a ReferenceError: FormData is not defined I thought FormData should be available in jsdom, but I can't figure out why it's not working? This test is meant to be ...

Access Select without needing to click on the child component

I am curious to learn how to open a Select from blueprint without relying on the click method of the child component used for rendering the select. <UserSelect items={allUsers} popoverProps={{ minimal: false }} noResults={<MenuItem disabled={ ...

The concept of a singleton design pattern is like a hidden treasure waiting to be

My approach to implementing the singleton pattern in a typescript ( version 2.1.6 ) class is as follows: export class NotificationsViewModel { private _myService: NotificationService; private _myArray: []; private static _instance: Notificatio ...

Exporting variables in Angular's Ahead of Time (AoT) compiler is

I recently attempted to incorporate dynamic configuration into my project, following a guide I found in this insightful post. While everything functions smoothly with the JiT compiler, I encountered the following error when attempting to build using the A ...

Typescript: Streamline the process of assigning types to enum-like objects

One common practice in JavaScript is using objects as pseudo-enums: const application = { ELECTRIC: {propA: true, propB: 11, propC: "eee"}, HYDRAULIC: {propA: false, propB: 59, propC: "hhh"}, PNEUMATIC: {propA: true, propB: ...

A guide on showcasing nested arrays data in an Angular application

info = [ { list: [ { title: 'apple'} ] }, { list: [ { title: 'banana'} ] } ] My goal here is to extract the list items. Here is how they are structured. desired r ...

Formatting dates in the Bootstrap Date Picker within Angular 6

When using Angular 6, I incorporate a date picker by adding the bsDaterangepicker class for selecting a date range. <input type="text" (ngModelChange)="dateFilterChanged($event)" [(ngModel)]="myDateField" value="{{ myDateField | date:'yyyy-MM-dd&a ...

What is the optimal method for navigating through a complex nested object in Angular?

Looking to navigate through a nested object structure called purchase. Within this structure, there is a sub-array named purchaseProducts which contains another sub-array called products along with additional data. What methods do you suggest for efficien ...

What type of HTML tag does the MUI Autocomplete represent?

Having trouble calling a function to handle the onchange event on an autocomplete MUI element. I've tried using `e: React.ChangeEvent`, but I can't seem to locate the element for the autocomplete component as it throws this error: The type &apos ...

Creating dynamic lists in Angular with ngFor: A step-by-step guide

I am currently working on an Angular 7 application and have a component that retrieves a JSON array. @Component({ selector: 'app-indices-get', templateUrl: './indices-get.component.html', styleUrls: ['./indices-get.component ...