I am trying to display a list of items that fit within categories. So this would be a list with two levels. How do I do this in Nativescript Angular?
For example, let’s say the list contains different continents, and each continent has its own countries. So I would want to display a list like:
Europe:
–France
–Germany
–Belgium
…
North America:
–Canada
–US
–Mexico
Africa:
–Nigeria
–Congo
…
Asia:
–Thailand
–China
…
The data has the form: continents = [{continentName: Europe, countries: {France, Germany,…}}, {continentName: North America, countries: {Canada, US,…}}, etc…}]
I am able to get the TS file to work fine (I am able to create the data–I know because the data shows up properly when I print to the console).
But I am not yet able to get the UI to display the items.
Using RadListView, here is one unsuccessful attempt:
<GridLayout>
<RadListView [items]="continents" (itemTap)="selectItem($event)">
<ng-template tkListItemTemplate let-continent="item" class="marginTop">
<Label text="{{continent.continentName}}"></Label>
<StackLayout *ngFor="let country of continent.countries">
<Label [text]="country"></Label>
</StackLayout>
</ng-template>
</RadListView>
</GridLayout>
This results just in displaying the continent names:
Europe
US
Africa
Asia
I have tried a few different things, like having RadListView within RadListView (instead of *ngfor), but nothing works yet–either just shows continents, shows blank screen, or throws error.
What would be the way to do this?
(I have simplified the data above–in my actual case, each country has its own attributes, like name, population, size, etc.–but thought it would be easier to understand in the simplified form above.)