How can I display “empName” and other details of this JSON in my table component in loop?
I’m using a third party API which provides a nested JSON object in return when I send employerID to the API URL.
After subscribing I’m storing the response in a var “AllPostedJobs”
{
"status": "All Jobs",
"result": [
{
"_id": "5c90fd3cfc7f3b0017803319",
"job_title": "Web Designer",
"job_desc": "test description ...",
"location": "Mangalore",
"experiance": "Freshers",
"job_type": "Full-Time",
"salary_package": "3L",
"job_keywords": "Photoshop, Illustrator",
"email_id": "[email protected]",
"employerID": "5c7e99c2a7a9eb00174de2b2",
"company_name": "Shreemithra Designs",
"AppliedStudentDetails": [
{
"_id": "5c9393c1a918d60017de7e55",
"empName": "Anup",
"empID": "5c939375a918d60017de7e53",
"job_title": "Web Designer"
}
],
"__v": 1
},
{
"_id": "5c913570cb78a100177ab23a",
"job_title": "Full Stack Developer",
"job_desc": "htjhsv dhsd jh jds fjshgdfkhsdmhfd;lw eiwiwemsd. This is a sample job description.",
"location": "Pune",
"experiance": "2 Years",
"job_type": "Part-Time",
"salary_package": "8L - 10L PA",
"job_keywords": "Angular, Node JS, React, HTML5. CSS3",
"email_id": "[email protected]",
"employerID": "5c7e99c2a7a9eb00174de2b2",
"company_name": "Shreemithra Designs",
"AppliedStudentDetails": [
{
"_id": "5c9393c9a918d60017de7e56",
"empName": "Anup",
"empID": "5c939375a918d60017de7e53",
"job_title": "Full Stack Developer"
},
{
"_id": "5ca60fa5ba17730017182ca8",
"empName": "Amit Pateriya",
"empID": "5c7795acfd39640017ca4c37",
"job_title": "Full Stack Developer"
}
],
"__v": 2
}
]
}
2
Answers
You can bind display data by binding controls in an HTML template to properties of your component.
The easiest way to display a component property is to bind the property name through interpolation. With interpolation, you put the property name in the view template, enclosed in double curly braces:
{{AllPostedJobs.status}}
.Or depending on your need you can hand over entire result data to another-component.
Now your another-component, should have
@Input
defined to handle the incoming data:In your another-component template:
now you can apply *ngfor easily, try this.