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

174
Views
Valor predeterminado de configuración angular para un cuadro combinado

En mi código, tengo un campo de entrada en forma de menú desplegable. El menú desplegable tiene 5 opciones (vacío, 1, 2, 3, 4). Las opciones 1, 2, 3 y 4 provienen de la base de datos y en la interfaz de usuario, quiero establecer el valor de entrada en 0 cuando elijo la opción vacía. Aquí está mi código y una captura de pantalla. ¿Qué debo hacer para establecer ese campo vacío como 0?

ingrese la descripción de la imagen aquí

HTML:

 <mat-form-field appearance="outline" fxFlex="100" fxFlex.gt-xs="30" class="w-100-p"> <mat-label>Dönem Hafta</mat-label> <mat-select formControlName="PlanWeek"> <mat-option *ngFor="let week of weekList" [value]="week.Id"> {{week.Name}} </mat-option> </mat-select> </mat-form-field>

TS:

 _productionService.onWeekListChanged.subscribe( (response: IBasicModel[]) => { this.weekList = response; } );
about 4 years ago · Juan Pablo Isaza
3 answers
Answer question

0

puede crear un elemento de opción y simplemente vincularlo a 0. La otra opción es iterar y vincular valores de la base de datos.

 <mat-option value="0"></mat-option> <mat-option *ngFor="let item of items" [value]="item.id">{{item.name}}</mat-option>
about 4 years ago · Juan Pablo Isaza Report

0

 <mat-option [value]="null">''</mat-option>

Para obtener más ejemplos, consulte la documentación de material angular.

Material angular MatSelect

about 4 years ago · Juan Pablo Isaza Report

0

Así es como puede definir una opción predeterminada en Mat-Select:

 <mat-form-field appearance="outline" fxFlex="100" fxFlex.gt-xs="30" class="w-100-p"> <mat-label>Dönem Hafta</mat-label> <mat-select formControlName="PlanWeek"> <mat-option [value]="0">default</mat-option> <mat-option *ngFor="let week of weekList" [value]="week.Id"> {{week.Name}} </mat-option> </mat-select> </mat-form-field>
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!