benjamincharity
1/21/2017 - 10:04 PM

Use an enum to build a select menu.

Use an enum to build a select menu.

public BarcodeFormatType = BarcodeFormatType;
public barcodeFormatTypes: string[];

ngOnInit(): void {
    // Expose an array of all barcode format types
    this.barcodeFormatTypes = Object.keys(BarcodeFormatType).filter(k => !isNaN(Number(k)));
}
    
<md-select
  placeholder="Barcode format"
  formControlName="barcodeFormat"
  name="barcodeFormat"
>
  <md-option *ngFor="let key of barcodeFormatTypes" [value]="key">
    {{ BarcodeFormatType[key] }}
  </md-option>
</md-select>