charbel
charbel

Reputation: 491

Angular not detecting change when calling array.sort()

I have an array of objects that i display using an "*ngFor" loop, when i call array.sort() changes occurs inside the array and the position/order of the elements changes but angular doesn't detect the changes and doesn't re-fires the "ngFor" loop. how can i update my UI after calling the sort function.

Upvotes: 2

Views: 1925

Answers (1)

Benny Halperin
Benny Halperin

Reputation: 2332

If a is your array, then try:

this.a = [...this.a.sort()];

Upvotes: 8

Related Questions