我有一个数组,保存4个数据:[onHour,onMinute,offHour,offMinute],我有4个数据,它们不在数组中。
<div class="on">
<mat-form-field appearance="fill" class="time_field">
<mat-label>minute</mat-label>
<input matInput type="number" formControlName="minute_glow_periodic" min="0" max="59">
</mat-form-field>
<mat-form-field appearance="fill" class="time_field">
<mat-label>hour</mat-label>
<input matInput type="number" formControlName="hour_glow_periodic" min="0" max="24">
</mat-form-field>
</div>
<div class="off">
<mat-form-field appearance="fill" class="time_field">
<mat-label>minute</mat-label>
<input matInput type="number" formControlName="minute_glow_periodic" min="0" max="59">
</mat-form-field>
<mat-form-field appearance="fill" class="time_field">
<mat-label>hour</mat-label>
<input matInput type="number" formControlName="hour_glow_periodic" min="0" max="24">
</mat-form-field>
</div>
字符串
在.ts组件中,我有这个变量periodicValues = [this.hourGlowPeriodic?.value, this.minuteGlowPeriodic?.value, this.hourSilencePeriodic?.value, this.minuteSilencePeriodic?.value];
,它通过提交按钮填充界面,但我不知道如何在ngOnInIt
上填充periodicValues[]
数组
我试过这种形式,但没有工作
this.form = this.formBuilder.group({
hour_glow_periodic: new UntypedFormControl({ value: this.data.element?.periodic_values[0], disabled: false }),
minute_glow_periodic: new UntypedFormControl({ value: this.data.element?.periodic_values[1], disabled: false }),
hour_silence_periodic: new UntypedFormControl({ value: this.data.element?.periodic_values[2], disabled: false }),
minute_silence_periodic: new UntypedFormControl({ value: this.data.element?.periodic_values[3], disabled: false }),
});
型
1条答案
按热度按时间o75abkj41#
您可以使用值
hour_silence_periodic
和minute_silence_periodic
更新HTML中的最后两个formControlName
,除此之外,根据提供的数据,您的代码似乎很好,请找到下面的工作示例,如果复制,请与问题共享。字符串
stackblitz