Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

298
Views
Seleccionar opciones de enumeración Angular

Tengo esta enumeración:

 export enum LogLevel { DEBUG = 'DEBUG', INFO = 'INFO', WARNING = 'WARNING', ERROR = 'ERROR' }

Me gustaría crear una selección en mi formulario, con para cada opción el texto enumerado como etiqueta:

 <select> <option value="DEBUG">DEBUG</option> <option value="INFO">INFO</option> <option value="INFO">INFO</option> <option value="INFO">INFO</option> </select>

¿Cuál es una forma correcta de hacer esto?

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

Intente usar Object.values para convertir la enumeración en una matriz:

 <select> <option *ngFor="let logValue of Object.values(LogLevel)" [ngValue]="logValue">{{}logValue}</option> </select>
about 4 years ago · Juan Pablo Isaza Report

0

aquí hay una solución simple

 1. content of app.component.ts: export class AppComponent { keys = Object.keys; logLevel = LogLevel; selected = LogLevel.DEBUG; select(event: any) { const value = event.target.value; this.selected = value; console.log(this.selected); } } export enum LogLevel { DEBUG = 'DEBUG', INFO = 'INFO', WARNING = 'WARNING', ERROR = 'ERROR', } 2. content of app.component.html <select [(ngModel)]="selected" (change)="select($event)"> <option *ngFor="let log of keys(logLevel)" [value]="logLevel[log]"> {{ log }} </option> </select>

para obtener más información, consulte este enlace https://stackblitz.com/edit/angular-ivy-cuhnbw

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!