我要完成的是更改StartHour的值(当startHour高于EndHour的值时)EndHour Value必须更改为StartHour加一小时。
<div class="startHourSelection">
<label *ngIf="startHourSelection">Begin uur</label>
<div *ngIf="startHourSelection" class="select">
<select id="starthour" (change)="onSelectStartHour($event.target.value)" [disabled]="parentIsLoading">
<option
*ngFor="let Hour of startHours; let i = index"
value="{{Hour}}"
[attr.selected]="i == 0 ? true : null">
{{Hour}}
</option>
</select>
</div>
</div>
<div class="endHourSelection">
<label *ngIf="endHourSelection">Eind uur</label>
<div *ngIf="endHourSelection" class="select">
<select id="endHour" (change)="onSelectEndHour($event.target.value)" [disabled]="parentIsLoading">
<option
*ngFor="let Hour of endHours; let i = index"
value="{{Hour}}"
[attr.selected]="i == 0 ? true : null">
{{Hour}}
</option>
</select>
</div>
</div>
组件:
两者的@Input都为false,我也知道我所有的时间都是字符串,而不是DATE,我不确定是否要转换它
@Output() selectStartHour = new EventEmitter<string>(); // when a strathour is selected
@Output() selectEndHour = new EventEmitter<string>(); // when a strathour is selected
startHours = [
'00:00', '01:00', '02:00', '03:00', '04:00', '05:00', '06:00', '07:00', '08:00', '09:00', '10:00', '11:00', '12:00',
'13:00', '14:00', '15:00', '16:00', '17:00', '18:00', '19:00', '20:00', '21:00', '22:00', '23:00'
];
endHours = [
'01:00', '02:00', '03:00', '04:00', '05:00', '06:00', '07:00', '08:00', '09:00', '10:00', '11:00', '12:00',
'13:00', '14:00', '15:00', '16:00', '17:00', '18:00', '19:00', '20:00', '21:00', '22:00', '23:00', '24:00'
];
onSelectStartHour(startHour: string) {
this.selectStartHour.emit(startHour);
}
onSelectEndHour(endHour: string) {
this.selectEndHour.emit(endHour);
}
答案 0 :(得分:0)
HTML文件更改
在两个选择元素中添加ngModel
。
例如:
开始时间选择:<select id="starthour" .... [(ngModel)]="startHour">
结束时间选择:<select id="endHour" .... [(ngModel)]="endHour">
TS文件更改
通过onSelectStartHour()
方法添加条件代码并更改endHours
的值。