lili
lili

Reputation: 1

Angular Post and show in html

I want to get the NAME data and show html. MY TS:

 this.httpClient.post<any>('http://localhost/test.php', {idd: this.idd},options)
    .subscribe((data) =>  {
      console.log(data);
      });

there are console.log display on tool.

HttpResponse {headers: HttpHeaders, status: 200, statusText: "OK", url: "http://localhost/test.php", ok: true, …}
body: Array(2)
0: {ID: "1", NAME: "LLI", EMAIL: "wqriehjfeoghetiogjetlgj", INFO: "hello"}
1: {ID: "2", NAME: "WII", EMAIL: "moiiooofgijtigjw", INFO: "hiiii"}

How to get ID value on HTML? thnak you....

Upvotes: 0

Views: 72

Answers (2)

FedG
FedG

Reputation: 1301

In .ts

response: any;

this.httpClient.post<any>('http://localhost/test.php', {idd: this.idd},options)
    .subscribe((data) =>  {
     this.response = data.body;//TRY THIS
      });

In .html

<div *ngFor="let item of this.respose">
  {{ item.ID}}
</div>

Upvotes: 1

Vikas Kandari
Vikas Kandari

Reputation: 1851

Your response is a array containing two sets of records so you have to go though loop to get each set's id something like below :

 this.httpClient.post<any>('http://localhost/test.php', {idd: this.idd},options).subscribe((data) =>  {
            for(var i = 0;i<data.length;i++){
              console.log(data[i].ID);
              console.log(data[i].NAME);
              console.log(data[i].EMAIL);
            }
 });

Upvotes: 0

Related Questions