您好,我创建了一个选择,显示当前年份、过去 5 年和未来 3 年。现在我想设置它,以便当前年份始终是默认值。这应该在反应形式中完成......你知道怎么做吗?
我的代码:
// HTML
<form [formGroup]="sendYearsForm">
<select class="upload_slc" id="upload_slc" required title="" formControlName="year"
(change)="sendYear($event)">
<option *ngFor="let years of sendYears" [value]="years">{{years}}</option>
</select>
<div class="select_arrow"></div>
</form>
// TS
sendYearsForm: FormGroup;
currentDate: Date = new Date();
selectedYear: number;
// Year form
this.sendYearsForm = this.fb.group({
year: [null]
});
// Show the current year with -5 and +3
this.selectedYear = this.currentDate.getFullYear(); // HThe current year is transferred here. How do I integrate it into the template?
for (let i = this.currentDate.getFullYear() - 5; i <= this.currentDate.getFullYear() + 3; i++) {
this.sendYears.push(i);
}
ABOUTYOU
暮色呼如
相关分类