Ravi Patel Ravi Patel - 10 days ago 6
JSON Question

Print Data from JSON Array in Template from Component

Here is My API Call and getting response in this.order.info

this.http.get(this.order_info_url+'/'+this.order_id)
.subscribe(
response => {
this.order_info = response.json();
console.log(this.order_info[0]);
},
error => {
alert(error.text());
return error.text();
}
);


And My Response is

{
"table1": [
{
"store_name": "Your Store",
"store_url": "http://localhost:8080/upload/",
"date_added": "2016-11-18T07:51:53.000Z",
"payment_method": "Cash On Delivery",
"shipping_method": "Flat Shipping Rate",
"firstname": "q",
"lastname": "q",
"Customer_Group_Name": "Default",
"email": "q@g.com"
}
],
"table2": [
{
"Customer_Notified": "NO",
"date_added": "2016-11-18T07:51:54.000Z",
"comment": "",
"name": "Pending"
}
]
}


How I get table1.store_name in my template from component.ts

Answer

You should get that value like this:

<p>{{ order_info?.table1[0].store_name }}</p>
Comments