如何解决在订阅中使用ngbDatePicker设置表单控件
当我从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 举报,一经查实,本站将立刻删除。