Problem encountered when attempting to retrieve information from a web service in Angular 4

I am currently attempting to retrieve data from a web service API.

However, all I can see is the data on the console.

The web service requires an ID, so I input the ID first and then proceed to obtain the data related to that ID within the web service using the following component:

HTML:

<form #educationForm="ngForm" method="post">
    <select [(ngModel)]="type_id"  name="type_id" class="rounded-inputs20  col-md-2"  id="getGrades">
        <option selected="selected">Education type...</option>
        <option  id="" *ngFor="let type_id of name_en" [ngValue]="type_id.id">{{type_id.name_en}}</option>
    </select>
</form>

<input type="button" name="previous" class="previous action-button-previous" value="Previous"/>
<input type="button" name="next" class="next action-button (click)="onSubmitGrade(educationForm)"  value="next"/>

<fieldset>
    <div class="col-md-12 text-center row schools">
        <div class="col-md-6"  *ngFor="let grade of grades">
            <h6 style="font-size: 26px;" name="grades"> 
            {{grade.name}}<input [value]="grade.id" id="select-all-grades6" type="checkbox">  
            </h6>
            <br>
        </div>
    </div>
</fieldset>

TS:

private educationType() {
return this._http.get('https://crm.easyschools.org/api/
en/schools/create/educationtypes')
  .subscribe(type_id => {
    this.id = type_id.id;
    this.name_en = type_id.data;
    console.log(type_id.data);
  });
}

onSubmitGrade(form: NgForm) {
let formData: FormData = new FormData();
// debugger;
formData.append('education_type_id', this.type_id);
this._http.post('https://crm.easyschools.org/api/en/schools/
create/getgrades', formData)
  .subscribe(grades => {
    // this.type_id = this.education_type_id;
    this.id = this.type_id.id;
    this.name = grades.data;
    console.log(grades.data);
  }, (err: HttpErrorResponse) => {
    console.log(err);
  });
}

The response I receive from the console appears as follows:

(13) [{…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}]
0
:
{id: 11, name: "Elementary", lessons_per_day: 5, lesson_duration: 
"08:21:20", day_start_at: "08:24:27", …}
1
:
{id: 13, name: "Secondary", lessons_per_day: 6, lesson_duration: 
"09:25:25", day_start_at: "10:29:00", …}
2
:
{id: 16, name: "Castor Sharp", lessons_per_day: 12, lesson_duration: 
"00:00:12", day_start_at: "17:30:00", …}
3
:
{id: 17, name: "Ifeoma Cochran", lessons_per_day: 12, lesson_duration: 
"00:00:04", day_start_at: "23:09:00", …}
4
:
{id: 18, name: "Jermaine Tyson", lessons_per_day: 12, lesson_duration: 
"00:00:14", day_start_at: "18:01:00", …}
5
:
{id: 19, name: "Quin Wells", lessons_per_day: 12, lesson_duration: 
"00:00:04", day_start_at: "11:25:00", …}
6
:
{id: 20, name: "Hiram Coffey", lessons_per_day: 12, lesson_duration: 
"00:00:04", day_start_at: "06:14:00", …}
7
:
{id: 21, name: "Shad Floyd", lessons_per_day: 12, lesson_duration: 
"00:00:04", day_start_at: "21:01:00", …}
8
:
{id: 22, name: "Oleg Ball", lessons_per_day: 12, lesson_duration: 
"00:00:41", day_start_at: "00:08:00", …}
9
:
{id: 23, name: "Ivory Gates", lessons_per_day: 12, lesson_duration: 
"00:00:41", day_start_at: "16:33:00", …}
10
:
{id: 24, name: "Serina Edwards", lessons_per_day: 12, lesson_duration: 
"00:00:41", day_start_at: "13:51:00", …}
11
:
{id: 25, name: "dsos", lessons_per_day: 44, lesson_duration: 
"00:00:45", 
day_start_at: "12:30:00", …}
12
: 
{id: 26, name: "Nissim Hurley", lessons_per_day: 12, lesson_duration: 
"00:00:04", day_start_at: "10:33:00", …}
length
:
13
__proto__
:
Array(0)

I am looking to display the data from the console on the screen, but my current code does not seem to be doing that effectively. Please feel free to use the provided API links to test and identify any missing elements in my code.

Answer №1

Your template does not currently include any declared grades. Make sure to declare a variable for grades and assign the response data to that variable.

grades :any = [];

Next, add the following code:

this._http.post('https://crm.easyschools.org/api/en/schools/ create/getgrades', formData) .subscribe(result=> { this.grades = result.data;}, (err: HttpErrorResponse) => { console.log(err); }); }

Alternatively, if you want to use an existing template, replace 'grades' with 'name':

 <div class="col-md-6"  *ngFor="let grade of name"

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

Exploring Angular 4.3 Interceptors: A Practical Guide

I am currently working on a new app that needs authorization headers. Normally, I follow a similar approach to what is described in this article on scotch.io. However, I have recently learned that Angular 4 now fully supports HTTP Interceptors through the ...

In what way does Ionic determine the URL for input and send the password-protected email for logging in based on that URL?

I've set up a section for inserting the URL into the login form page using the following code: <ion-item> <ion-label floating>Company URL</ion-label> <ion-input type="url" value="" required></ion-input> </ion-item> ...

TypeScript compilation error caused by typing issues

My current setup includes typescript 1.7.5, typings 0.6.9, and angular 2.0.0-beta.0. Is there a way to resolve the typescript compile error messages related to the Duplicate identifier issue caused by typings definition files? The error message points ou ...

Is error propagation from nested Promise to parent Promise not working properly in Node.js?

I'm currently working on a Node.js/TypeScript API with Express. Below is a snippet from my get method where I encountered an error in the format function. The error is caught by the promise, but it doesn't propagate to the parent promise after th ...

How to count the array index in PHP and change an integer to a string

In my mysqli query, I retrieved an array that contains a list of tasks. My goal is to count the number of tasks in the array (i.e., the number of rows) and display this as a human-readable number on an icon badge. try { $db = new PDO("mysql:host= ...

Conditional Rendering with Next.js for Smaller Displays

I've implemented a custom hook to dynamically render different elements on the webpage depending on the screen size. However, I've noticed that there is a slight delay during rendering due to the useEffect hook. The conditionally rendered element ...

Validation of the JSON schema has encountered an error. The value in the array does not meet the requirement as it should be either a null or an object. This issue has been identified in

Summary: I encountered an error message regarding JSON schema validation when working with a custom HTTPS Sample Request payload that includes arrays. The error specifically states that the array requires an object or null value, but found an array instea ...

Customizable mongoDB database collection

Is there a more efficient way to make calls to different collections based on a function parameter? I'm exploring the possibility and if it's not feasible, I'll handle it case by case. Currently, I have this code and the goal is to have a u ...

Is it no longer possible to instantiate an object using the syntax <interface>{}?

There seems to be an issue with the code snippet below when run in the TypeScript playground: interface Person { name: string; age: number; } const makePerson= function(name : string, age : number) : Person { let obj = <Person>{} ...

Check if a value is present in the array with *ngIf

I'm curious about how to use the ngIf directive in a specific scenario. In my Angular application, I have dynamically generated angular material toggles, each with a unique id. I'm familiar with using ngIf to conditionally display elements on the ...

Guide to correctly passing custom parameters along with the event object to an asynchronous form submission handler

Asking for guidance on defining and typing custom parameters alongside the native event object in an async onSubmitHandler for a form. The current implementation only receives the native event as a single parameter: const onSubmitHandler: FormEventHa ...

Combining two AngularJS scopes into one without merging them

I'm attempting to merge two scopes into one with a unique set of labels. I'm not sure if this is doable, but here's where my code stands at the moment. .controller('eventsCtrl', ['$scope', '$rootScope', &apos ...

Using a basic XML file in Angular: A beginner's guide

Incorporating XML into my Angular app is a necessity. While the most straightforward approach would be to store it as a string, like so: xml = '<?xml version="1.0" encoding="UTF-8"?>\n' + '<note>\n ...

Organizing files in an ExpressJs project with Angular2

What is the conventional file structure for a mix of ExpressJs and Angular2 projects? Here's my current setup: Project | |--bin |--node_modules |--public |--images |--javascripts |--stylesheets |--routes |--views |--app.js |-- ...

Angular reference numbers vs ngModel

When is it necessary to use [(ngModel)] on an input, and when can I simply use #reference? For instance: <div class="form-group"> <div class="input-group mb-2"> <input type="text" class="form-control" [(ngModel)]="newUser"> < ...

What is the best way to merge two interfaces and convert all of their fields to optional properties?

I have two unalterable interfaces: interface Person { name: string; age: number; } interface User { username: string; password: string; } I aim to merge them into a single interface called Player // please, adjust this code accordingly interfac ...

I am interested in monitoring for any alterations to the @input Object

I've been attempting to detect any changes on the 'draft' Object within the parent component, however ngOnChange() does not seem to be triggering. I have included my code below, but it doesn't even reach the debugger: @Input() draft: ...

I am experiencing an issue with my date filter where it does not display any results when I choose the same date for the start and end dates. Can anyone help me troub

Having an issue with my custom filter pipe in Angular. When I select the same dates in the start and end date, it doesn't display the result even though the record exists for that date. I've noticed that I have to enter a date 1 day before or ea ...

Program crashes due to strcpy function

I am currently working on a program that reads date and time entries (e.g., 29/11/2021-15:33:56) from a file and saves them in an array. The task at hand involves creating a function (timeStampToSeconds) to convert these entries into long integers. Once we ...

Connect the keys from one enum to either keys or values in another enum

When working with the code below, it is important that the keys of PropertiesNamesInDataBase align with those in User.Keys. While the values of PropertiesNamesInDataBase are used in the backend, it is crucial for uniformity that the names match in the fron ...