Displaying nested web service array data in Angular 4

I created a project that retrieves data from a web service API. However, the API contains nested arrays that also need to be displayed. How can I access the data from these nested JSON arrays? What is the correct way to extract this data within the HTML code in order to display it properly? Interestingly, the initial objects are being fetched correctly, but the issue arises with the nested objects.

Below is a screenshot of the response from Postman:

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

To access the API, please follow this link: API Link

If you'd like to view the project on Stackblitz, click on this link: Project Link

To see the issue I am encountering, simply click on "sign in without user or password," then choose any school, and finally navigate to the divisions section within the project. The specific component I am referring to is the divisions component.

Answer №1

From what I recall, the data you're looking for is readily available. Simply navigate through the dots to access the necessary information: response.data[0].grade[0].classes[1].grade_id

Here's how you can achieve this in the template:

<div *ngFor="let division of divisionList">
    <div *ngFor="let grade of division.grade">
        <div *ngFor="let class of grade.classes">
            <span>{{ class.grade_id }}</span>
        </div>
    </div>
</div>

To get started in your component, try this:

<ng-container *ngIf="divisionList">
    <button name="American Primary"  
        *ngFor="let division of divisionList"
        class="choose-list arrow-onclick1" data-toggle="collapse" data-target="#list1">
           {{division.name}}
         <i class="fa fa-arrow-right pull-right arrow-down-onclick1" 
            aria-hidden="true" style="margin-top:12px"></i>
    </button>
    <a routerLink="/editaisdivision" 
        style="text-decoration: none;">
       <span class="fa fa-pencil pen-pen-pen" aria-hidden="true" 
             style="margin-left: 10px; color: #171b5e;"></span>
     </a>
</ng-container>

Keep in mind that using two structural directives within one tag is not allowed, hence the ng-container.

Answer №2

Simply employ the JSON.parse(JSON_DATA) method to transform your JSON string into a JavaScript 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

The specified control name formControlName in the Angular reactive form cannot be located

Having encountered this issue multiple times on Stack Overflow without any success, I am reaching out for help to identify what I might be doing wrong. In my component : ngOnInit() { this.companyCreatForm = this._formBuilder.group({ name: [null, ...

The Problem of Unspecified Return Type in Vue 3 Functions Using Typescript

Here is the code snippet I am working with: <template> <div> <ul v-if="list.length !== 0"> {{ list }} </ul> </div> </template> < ...

What is the best way to extract data from Azure Data Lake and showcase it within an Angular-2 interface?

I am facing a challenge where I need to retrieve files with content from Azure Data Lake and display them in an Angular-2 Component. The issue is that when using the List File Status() method, I am only able to obtain file properties, not the actual conten ...

Emitter fails to emit the value

I've been working on a filter component that looks like this: <app-filter (newStatusValue)="changeListByStatus($status)" However, I'm running into an issue where nothing is being output... changeListByStatus($status){ console.log('ch ...

Elastic Beanstalk hosted apps do not support the transmission of large files

I've been working on a web application that requires storing large files, specifically mp4 videos with sizes sometimes exceeding 100mb. However, I encountered an error when trying to upload these files from a static Angular website hosted in an S3 buc ...

Vue.js with TypeScript: The property 'xxx' is not found on the type 'never'

I have a computed method that I am trying to execute: get dronesFiltered(){ const filtered = this.drones.filter((drone) => { return drone.id.toString().indexOf(this.filterId) > -1 && drone.name.toLowerCase().toString().in ...

"assurance of not issuing a return value in the correct order

Hey everyone, I'm a newcomer to the world of Ionic! I'm looking to pull data from pouch-db in the background. After some research, it seems like promises are the way to go. My goal is to have my console logs display in the order: 1, 2, and then ...

What methods can I employ within an AngularJS controller to retrieve data from Google App Engine instead of solely relying on a JSON file?

As a newcomer to web development, I have been experimenting with retrieving data from a Google App Engine datastore and selectively displaying it on a webpage using AngularJS. While I have successfully integrated Angular with a JSON file and posted the con ...

How can you make sure that VS Code always utilizes relative paths for auto imports in TypeScript?

VS Code has been automatically importing everything using Node-like non-relative paths relative to baseUrl, which is not the desired behavior. Is there a way to instruct VS Code to import everything with relative paths, excluding Node modules? Removing t ...

Following an AJAX post within the MVC framework, the URL becomes excessively lengthy

http://localhost:53435/Blog/BlogIndex?title=blog+title&seo=seo&content=%3Cp%3Econtent%3C%2Fp%3E%0D%0A the URL listed above Whenever I click the save button, the page refreshes and the URL appears like that. I do not want it, how can I resolve th ...

Incorporate a new data field within a JSON array

I recently received a JSON string containing an array structured like this: { "Id": 123, "Username": "Sr. X", "Packages": [ { "Name": "Cups", "SupplierId": 1, "ProviderGroupId": 575, "SupplierName": "Foo Cups" }, ...

Updating JWT token with Angular 5 Http Interceptor

I have successfully implemented token saving, retrieving logic and a refreshing call. However, I am facing an issue where when I intercept a 403 error in my HttpInterceptor, other simultaneous calls also trigger a token refresh. I would like to find a wa ...

When working with Angular 5, the question arises: how and where to handle type conversion between form field values (typically strings) and model properties (such

As a newcomer to Angular, I am struggling with converting types between form field values (which are always strings) and typed model properties. In the following component, my goal is to double a number inputted by the user. The result will be displayed i ...

Reference for the WinRT DataServiceContext service supporting version 5.2.0.0 of Microsoft.Data.Services.Client.WindowsStore

Will the WCF Data Services Tools for Windows Store Apps be updated to support v5.2 (or even better 5.3) soon? The JSON light format is essential for my remote workers who need to push/pull entities occasionally. It seems like it hasn't been updated ...

I have encountered limitations with useFormik where it does not accept null values for initialValues, even while utilizing a validationSchema

I am currently utilizing the useFormik hook to handle my form. The userId field is a select, so by default its value is set to null. However, my validationSchema requires this field to be populated before submission. const formik = useFormik<ApiCredit ...

How do I properly type when extending Button and encountering an error about a missing component property?

Currently in the process of transitioning from MUI v3 to v4. My challenge lies with some Button components that are wrapped and have additional styling and properties compared to the standard Material UI Button component. Ever since upgrading to v4, I&apos ...

Interface constructor concept

Trying to figure out how to dynamically add different types of components to a game object in TypeScript. After consulting the TypeScript documentation on interfaces, I discovered a unique approach for dealing with constructors in interfaces, which led me ...

Forming a JSON structure using input variables

Currently, I am attempting to construct a JSON object using variables extracted from a form. var firstName = $('#firstName').val(); var lastName = $('#lastName').val(); var phone = $('#phoneNumber').val(); var address ...

Issue with DTO and a custom decorator in NestJS

I am currently facing an issue with using a DTO alongside a custom decorator within a NestJS controller for body validation. I am sending a request using multipart/form data, which requires me to parse the data from a string to JSON. However, when attempti ...

How to efficiently deserialize JSON into a List of objects using Kotlin and Jackson without encountering a Deserialization Exception

I have been using the following link to learn how to read values using a mapper from a JSON string, but I encountered a deserialization exception while executing my code. How to use jackson to deserialize to Kotlin collections Code: private fun parseCou ...