Reputation: 940
I am working in an angular4 application in this I need to bind a drop-down from API response data .
I don't know how to fetch the specific data for the particular section from API.
Here API contains Category ,Group and Sub-group data .Each Group has 2 sub-groups.
I have created a stackblitz file for this Please take a look
https://stackblitz.com/edit/angular-bootstrap-carousel-dynamic2-y6iknh?file=app%2Fapp.component.ts
Here I receiving the API response ,But don't know how to assign the values to the dropdown positions.
Can anyone guide me to solve this ..
Upvotes: 0
Views: 3862
Reputation: 86740
You need to bind data with some variable by parsing it into json()
, then you will be able to fetch and consume data into your view like this
ngOnInit() {
this.CartdataService.get_New_Products().subscribe(
data => {
this.dropdownData = data.json();
console.log(data.json());
});
<div class="col-sm-12" style="margin-top: 20px !important" *ngFor='let data of dropdownData; let i=index'>
<div class="col-sm-12 opt1">
<div class="row">
<h5>
<a class="col-sm-12 font-weight-normal">
{{data?.CAMD_ENTITY_DESC}}
</a>
</h5>
<i class="fa fa-angle-down ind" data-toggle="collapse" [attr.href]="'#collapseExample' + data?.CAMD_ENTITY_DESC"></i>
</div>
</div>
<div class="col-sm-12 collapse opt1" [id]="'collapseExample' + data?.CAMD_ENTITY_DESC"
*ngFor='let group of data?.group; let j=index'>
<div class="row">
<h6>
<p class="dropdown-item col-sm-10">{{group?.CAMD_PRGRP_DESC}} </p>
</h6>
<i class="fa fa-angle-down ind arrow" data-toggle="collapse" [attr.href]="'#innerCollapse' + group?.CAMD_PRGRP_DESC"></i>
</div>
<div class="collapse col-sm-12" [id]="'innerCollapse' + group?.CAMD_PRGRP_DESC">
<div class="row" *ngFor='let subgroup of group?.subgroup; let i=index'>
<h6>
<a class="dropdown-item opt">{{subgroup?.CAMD_PRSGRP_DESC}}</a>
</h6>
</div>
</div>
</div>
</div>
Here is working example for the same
Upvotes: 2