I have a error like this... The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type.
I have shown in MDN explanation and I am not finding where is the problem. When I delete the month from this.Months.push then the sorting it is working but it is showing in dropdown only numbers not the text with months there. Here is my code.
This is the HTML.
<app-dropdown [ngModel]="selectedMonths" [multiSelect]="true" label="Select Month" labelWidth="75px" optionWidth="150px" [items]="Months" (ngModelChage)="monthChange($event)">
</app-dropdown>
This is the TS
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); // here is saying me the failure.
month
,months
,Months
,monate
— have you considered some basic cleanup? And obviously the issue is, thatmonth
is not anumber
array. – qqilihq