大佬教程收集整理的这篇文章主要介绍了angular – 使用hasError()进行验证的表单生成器抛出错误ERROR TypeError:无法读取未定义的属性’hasError’,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
在component.ts中,我使用formGroup实现了我的表单
以下是我的代码
public myForm: FormGroup; constructor(private authenticateservice: Authenticateservice,private _fb: FormBuilder ) { } ngOnInit() { this.myForm = this._fb.group({ address: [thiS.UserDetails.address,[<any>Validators.required]],address2: ['',city: ['',company_address: ['',company_address2: ['',company_city: ['',company_country: ['',company: ['',[<any>Validators.required,Validators.minLength(3)] ],company_tax_number: ['',company_zip: ['',Validators.minLength(5),Validators.maxLength(7)]],country: ['',email: ['',Validators.email]],first_name: [thiS.UserDetails.first_name,id: ['',last_name: ['',phone: ['',Validators.minLength(10)]],zip: ['',user_type: ['2',terms: [0,hash_tag: [''],}); }
它工作正常.但是在frontEnd中显示验证时
我这样用过
<div class="form-group row"> <div class="col-lg-8"> <label>Address 2</label> <textarea class="form-control" placeholder="Address" rows="2" [readonly]="disabled" id="companyaddress2" formControlName="company_address2"></textarea> <span class="Help-block form-error text-danger small" *ngIf="myForm.controls['company_address2'].hasError('required')">Company Address 2 is required.</span> </div> </div>
它正在工作,但在控制台中抛出错误,如下
错误TypeError:无法读取未定义的属性’hasError’
请帮我解释一下这个问题.
谢谢.
<span class="Help-block form-error text-danger small" *ngIf="myForm.controls['company_address2'].errors?.required && myForm.controls['company_address2'].touched">Company Address 2 is required </span>
以上是大佬教程为你收集整理的angular – 使用hasError()进行验证的表单生成器抛出错误ERROR TypeError:无法读取未定义的属性’hasError’全部内容,希望文章能够帮你解决angular – 使用hasError()进行验证的表单生成器抛出错误ERROR TypeError:无法读取未定义的属性’hasError’所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。