In Angular 2 latest RC context I try to build a view with several tabs. Data come from an API where I need to make calls in two steps to retrieve targeted data.
- Each tabs contains accordion groups and relate to
categories
- Each accordion groups contains bullet list and relate to
categories[i].subtopics
This part works perfectly well.
Things become more tricky when I try to implement the <li>
tag with data coming from a second array subTopics
.
I try several combinations of *ngFor="let services of subTopics
without success.
What are y options to display the way I want (see comment in HTML template)
My component HTML
<tabset>
<tab heading="{{category.name}}" *ngFor="let category of categories | orderBy" >
<h2>Content</h2>
<accordion>
<accordion-group heading="{{subtopic.name}}" *ngFor="let subtopic of category.subtopics | orderBy">
<li>
<!-- Here is where I want to display value for each services.name key related to my subtopic. -->
</li>
</accordion-group>
</accordion>
</tab>
My categories
JSON
My categories
array structure looks like this.
After retrieving this object I iterate over each categories[index].subtopics
in order to generate my subTopics
array.
[{
"code": "FIRST_CATEGORY",
"name": "First Categories", //Tab heading
"subtopics": [{
"code": "CODE1",
"name": "Name for Code 1" //Accordion group heading
}, {
"code": "CODE2",
"name": "Name For Code 2" //Accordion group heading
}]
},{
"code": "SECOND_CATEGORY",
"name": "Second Categories", //Tab heading
"subtopics": [{
"code": "CODE3",
"name": "Name for Code 3" //Accordion group heading
}, {
"code": "CODE4",
"name": "Name for Code 4" //Accordion group heading
}]
}]
My subTopics
JSON
My subTopics
array structure looks like this. I simplify it a lot, as there is many key/value per services
.
[{
"subtopic": "CODE1",
"services": [{
"code": "755",
"name": "The Name of My Code 755" //my <li> Tag
}, {
"code": "199",
"name": "The Name of My Code 199" //my <li> Tag
}]
}, {
"subtopic": "CODE2",
"services": [{
"code": "761",
"name": "The Name of My Code 761" //my <li> Tag
}, {
"code": "356",
"name": "The Name of My Code 356" //my <li> Tag
}]
}]
This array is build using this function where code
and index
coming from my categories
array iteration.
getSubServicePerTopic(code, index){
this._dxdService.getSubTopics(code, this.regionId)
.subscribe(subTopics => {
this.subTopics[index] = subTopics;
});
}