I've recently started with typescript. I've created a dropdown using select and option tags in the template.
<select [(ngModel)]="primaryMode" (ngModelChange)="primaryModeChangeHandler($event)">
<option *ngFor="let mode of modes" [value]="mode">{{mode}}</option>
</select>
and in typescript I was having an array:
modes= ['Calendar Year', 'Year-to-date', 'Rolling Year', 'Custom'];
But my tech lead said that I've to use enum instead of array. Here's my code now:
import { Component, OnInit, ... } from '@angular/core';
export enum presetRange {
CalendarYear,
YearToDate,
RollingYear,
CustomRange
}
@Component({
selector: 'app-timeselector',
templateUrl: './timeselector.component.html',
styleUrls: ['./timeselector.component.css']
})
export class TimeselectorComponent implements OnInit {
constructor() { }
ngOnInit() {
}
primaryMode;
primaryModeChangeHandler(event) {
console.log(this.primaryMode);
}
}
But the problem is that I don't know how to bind dropdown to an enum. I tried few things but I failed. Here's the stackblitz. Please correct me where I'm wrong.