I Have a server response, consisting of an object and array of objects like below:
{
"bookNumber": "123214",
"Desc": "book desc",
"title": "title here",
"published": "12/01/2016",
"author": {
"authorname": "VictorA"
},
"Category": [{
"genere": "Type1",
"number": "2331",
"sesction": "Fiction"
}, {
"genere": "type2",
"number": "430359",
"sesction": "Kids"
}, {
"genere": "type2",
"number": "436430",
"sesction": "Kids"
}, {
"genere": "type2",
"number": "123914",
"sesction": "Kids"
}],
"Publisher": [{
"name": "Pubbook",
"pubId": "81.25402-0233",
"lastModified": "2012-02-09"
}]
}
On the component i subscribe to the Observable from the service like below:
this.myService.getDetails(id).subscribe (data => {
this.resp = data;
console.log (JSON.stringify(this.resp));
})
in the HTML:
I'm using *ngFor to loop through response like below:
<div class="panel-group" id="accordion">
<div class="panel panel-default" id="panel1">
<div class="panel-heading">
<h4 class="panel-title">
<a data-toggle="collapse" data-target="#collapseOne"
href="#collapseOne">
Book
</a>
</h4>
</div>
<div id="collapseOne" class="panel-collapse collapse in">
<div class="panel-body"></div>
{{bookNumber}}
...so on
</div>
</div>
<div class="panel panel-default" id="panel2">
<div class="panel-heading">
<h4 class="panel-title">
<a data-toggle="collapse" data-target="#collapseTwo"
href="#collapseTwo" class="collapsed">
Documents
</a>
</h4>
</div>
<div id="collapseTwo" class="panel-collapse collapse">
<div class="panel-body" *ngFor = "let item of resp.Category"></div>
// here How can I extract items based on genere type e.g. Type1 <div col="md-6"> {{items of Type1 genere}} {{}}</div>
// Type2 <div col="md-6">{{items of Type2 genere}}</div>
I want to display details of each Genere in separately and update on selection for e.g. when i click Number 2331 get details of that object, and same for 4302359
</div>
</div>
</div>
How to loop over Category array based on Genere Type(1,2...etc) and update details of each item once user click on number?