Reputation: 3
I have json result like this
{
"modelList":["modelName1","modelName2"],
"modelNamesList":["modelName1","modelName2"],
"yearList":["2021","2020","2019","2018"]
}
I need only years list from above object so I am not getting how to do that, can anyone help me, thank you
I have done something like this
home.component.ts
export class HomeComponent implements OnInit {
catlogData: any ={
"modelList":["modelName1","modelName2"],
"modelNamesList":["modelName1","modelName2"],
"yearList":["2021","2020","2019","2018"]
};
ngOnInit(): void {}
home.component.html
<ul *ngFor="let a of catlogData">
<li>year:{{a.yearList[i]}}
</li>
</ul>
Upvotes: 0
Views: 39
Reputation: 4480
You can directly access the yearsList
from catlogData
since it's an Object(catlogData.yearsList
). Incase if you want iterate whole catlogData
object, Check this answer
Try like this
<div>
<ul *ngFor="let year of catlogData.yearList">
<li>years: {{ year }}</li>
</ul>
</div
Upvotes: 2