当用户打开对话框时,我想在当前日期自动设置日期选择器,但我不知道如何操作。
此外,我何时在Code_personnel上进行验证,以验证Code_personnel是否恰好等于4个字符,因此我需要使用哪种类型的验证属性?
我的html:
<form [formGroup]="profileForm" class="event-form w-100-p" fxLayout="column" fxFlex>
<div fxFlex="1 0 auto" fxLayout="column" fxLayout.gt-xs="row">
<mat-form-field appearance="outline" class="pr-sm-8" fxFlex="50">
<mat-label>Code personnel*</mat-label>
<input matInput formControlName="Code_personnel">
<mat-error>Code personnel doit composer par 4 chiffres.</mat-error>
</mat-form-field>
<mat-form-field appearance="outline" class="pr-sm-8" fxFlex="50">
<mat-label>N de tel</mat-label>
<input matInput formControlName="N_tel">
</mat-form-field>
</div>
<div fxFlex="1 0 auto" fxLayout="column" fxLayout.gt-xs="row">
<mat-form-field appearance="outline" class="pr-sm-8" fxFlex="100">
<mat-label>Date de naissance</mat-label>
<input matInput [matDatepicker]="startDatePicker" formControlName="birthday">
<mat-datepicker-toggle matSuffix [for]="startDatePicker"></mat-datepicker-toggle>
<mat-datepicker #startDatePicker></mat-datepicker>
</mat-form-field>
</div>
</form>
</div>和组件:
now;
profileForm = this.fb.group({
Nom_de_famille: ['' ,Validators.required],//
Prénom: ['' ,Validators.required],//
email: ['', [Validators.email,Validators.required]],//
Code_personnel: ['', Validators.required],//I need here aad the 4 charectres validation
N_tel: [''],
birthday: [new Date()],//I have tried that
adresse: [''],
lieu:[''],
CIN:['',Validators.required],
Genre:[''],
N_permis:[''],
Département: ['',Validators.required]
});
ngOnInit() { this.now = formatDate(new Date(), 'yyyy/MM/dd', 'en');
}发布于 2020-04-07 19:54:30
在组件中:
startDate = new Date();Date()为您提供当前时间。
在html中:
<mat-datepicker [startAt]="startDate"></mat-datepicker>mat-datepicker的startDate属性设置日历中的给定月份和年份。
https://stackoverflow.com/questions/61079139
复制相似问题