I get my data from my API, I have already made my call and I display it.
I would like to order it alphabetically.
I don't understand why my console say : 'ERROR TypeError: Cannot read properties of undefined (reading 'sort')'
CodePudding user response:
Because you are getting the clubs in one async operation and you launch sort operation immediately and the data didn't arrive yet. You must chain the operation:
constructor(...) {
this.getClubs().subscribe(clubs => {
this.clubs = clubs;
this.sortClubs();
});
}
private getClubs() {
return this.httpClient.get('...')
}