Angular keyvalue pipe sort properties / iterate in order

Hi for loop in angular 8 showing alphabetical order <select class="cs1 form-control" id="monthselector" [(ngModel)]="currentmonth"> <option> --Select Month-- </option> <option *ngFor="let dateforMonthdays of dateforMonth | keyvalue: originalOrder" value="{{dateforMonthdays.key}}">{{dateforMonthdays.key}}</option> </select>
Ankur Rajput
Asked 07-01-2021

Answer (1)
Hi, You can try this code, it is working Fine in my project. In Template file you can  write below code after constructor. originalOrder = (a: KeyValue<number,string>, b: KeyValue<number,string>): number => {       return 0; And in html component file you can write below code. write this code in ngfor pipe keyvalue. <select class="form-control"  id="test" [(ngModel)]="testing">         <option> --Select category--</option>           <option   *ngFor="let categoryList of categoryLists | keyvalue: originalOrder"   value="{{categoryList.key}}">{{categoryList.key}}</option>                            </select>  
Faisal Khan
Asked 08-01-2020
Need to  import KeyValue in .ts file.
import { KeyValue } from '@angular/common';
By : Faisal Khan | 09-01-2020 | 45 Likes
Write comment

Submit your answer