Hi!
I have a page with a list and I want to order the list items. I tried it with the javascript function sort() to sort the array in the .ts file, but that didnt work. Here is my code:
.html:
...
<ion-content padding class="categories">
<ion-list>
<ion-item *ngFor="let category of categories">
{{category}}
</ion-item>
</ion-list>
</ion-content>
.ts:
...
categories: Array<any>;
constructor(private nav: NavController, public listService: ListService) {
this.loadCategories();
this.categories.sort();
}
loadCategories() {
var categories = [];
this.listService.load()
.then(data => {
data.forEach(function (list) {
if (categories.indexOf(list.category) == -1) { // Every category only one time
categories.push(list.category);
}
});
});
this.categories = categories;
}
The list service gives me an extern json file and I store for every json object the ācategoryā value. And every category should be an item of the list. And I want to sort them. What can I do?