This is the select I have for the year, I need the current year to be selected by default and then collect that data in the back.
This is the html:
<mat-form-field fxFlex="25">
<mat-select #selectedYear placeholder="Year" formControlName="yearUser">
<mat-select-search [matSelect]="selectedYear"></mat-select-search>
<mat-option *ngFor="let year of years" [value]="year">{{ year }}</mat-option>
</mat-select>
</mat-form-field>
This is the ts:
selectedYear: number;
years: number[] = [];
constructor(
private fb: FormBuilder,
private msgs: MessageService,
private sessionService: SessionService,
private dashboardService: DashboardService,
private router: Router,
private uiUtils: UIUtilsService,
private employeeService: EmployeeService,
) {
this.selectedYear = new Date().getFullYear();
for (let year = this.selectedYear; year >= 2020; year--) {
this.years.push(year);
}
}
question from:
https://stackoverflow.com/questions/65883543/angular-mat-select-default-selection 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…