1private isAscendingSort: boolean = false;
2
3sortUser() {
4 console.log('sorting!'); // just to check if sorting is being called
5 this.isAscendingSort = !this.isAscendingSort; // you missed this
6
7 this.items.sort((item1: any, item2: any) => this.compare(item1, item2));
8}
9
1let isAscendingSort: Boolean = true;
2sortUser() {
3 console.log('sorting!'); //just to check if sorting is beng called
4 this.items.sort((item1: any, item2: any) => this.compare(item1, item2));
5 }
6 // Sort
7 compare(item1: any, item2: any): number {
8 let compValue = 0;
9 compValue = item1.attributes.fullName.localeCompare(item2.attributes.fullName, 'en', {
10 sensitivity: 'base'
11 });
12 console.log(compValue);
13 if (!this.isAscendingSort) {
14 compValue = compValue * -1;
15 }
16 return compValue;
17 }
1<button (click)="sortData()">Sort Data</button>
2<div *ngFor="let item of items">
3{{items.attributes.fullName}}
4</div>