问题描述
当我从GET请求获取用户数据时,我需要使用ngbDatePicker设置表单控件,这是Input:
<input
type="text"
[(ngModel)]="birthDate"
[placement]="'bottom'"
class="form-control"
id="birthdate"
[maxDate]="maxDate"
placeholder="yyyy-mm-dd"
name="birthdate"
[minDate]="{ year: 1940,month: 1,day: 1 }"
ngbDatepicker
#d="ngbDatepicker"
formControlName="birthdate"
[ngClass]="{
'is-invalid': !personalData.get('birthdate').valid && personalData.get('birthdate').touched
}"
(click)="d.toggle()"
/>
日期格式还可以,但是值重置状态,因为我猜这是在预订函数中。 formGroup代码:
this.personalData = this.formBuilder.group({
name: ['',Validators.required],lastName: ['',null],motherName: ['',secondLastName: ['',email: ['',[Validators.email,Validators.required]],phoneNumber: [null,[Validators.required,Validators.pattern(/^[+]*[(]{0,1}[0-9]{1,4}[)]{0,1}[-\s\./0-9]*$/)]],gender: ['male',birthdate: [null,ufBirth: [null,municipalityBirth: [null,nacionality: ['',originCountry: [null,inmigrationDate: ['',breed: [null,education: [null,familySituation: [null,cep: ['',uf: [null,city: [null,neighborhood: ['',street: ['',streetNumber: [null,Validators.pattern(/^(?=.*[0-9])/)]],});
birthDate: NgbDateStruct;
this.birthDate = {
year: moment(user.personalData.birthdate).year(),month: moment(user.personalData.birthdate).month(),day: moment(user.personalData.birthdate).day(),};
this.personalData.get('birthdate').setValue({
year: moment(user.personalData.birthdate).year(),});
我尝试过几次以将值设置为可以正常工作,我的意思是1.格式化该值,2.设置该值,然后3.进行表单验证。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)