I encountered an error message that reads: "The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type."
After reviewing the MDN explanation, I am still struggling to identify where the problem lies. When I remove the month from this.Months.push, the sorting works fine, but only numbers are displayed in the dropdown menu instead of the text representing the months.
Below is my code snippet:
<app-dropdown [ngModel]="selectedMonths" [multiSelect]="true" label="Select Month" labelWidth="75px"
optionWidth="150px" [items]="Months" (ngModelChage)="monthChange($event)">
</app-dropdown>
This is the TypeScript code snippet:
purchaser: Map<string, Purchased>;
months: number [] = [];
Months: DropdownOption[] = [];
const monate = [
'January',
'February',
'March',
'Aprill',
'Mai',
'June',
'July',
'August',
'September',
'October',
'November',
'December'
];
this.purchaser.forEach(purchaserId => {
if (!this.months.includes(purchaserId.created.getMonth())) {
this.months.push(purchaserId.created.getMonth());
this.Months.push({key: purchaserId.created.getFullYear().toString(), value: month[purchaserId.created.getMonth().toString()]});
}
});
this.Months.sort((a, b) => +a.value - +b.value);
this.months.sort((a, b) => a - b);
month.sort((a, b) => a - b); // The error occurs at this line