我正在使用嵌套的FormGroup,并且在html FormGroup中是父级 formGroup和技能是嵌套表单,但是在验证控件上是 找不到。谁能帮上忙。提前致谢。
ngOnInit() {
this.studentForm = new FormGroup({
fullName: new FormControl('', Validators.required),
email: new FormControl('', [Validators.required, Validators.email]),
skills: new FormGroup({
skillName: new FormControl(),
ExperienceInYears: new FormControl(),
Proficiency: new FormControl()
})
})
html ---
<div formGroupName='skills'>
<div class="form-group">
<label for="Email1">Skill Name</label>
<input type="text" class="form-control" formControlName='skillName' placeholder="Skill Name">
<div *ngIf="studentForm.controls['skills'].controls[skillName].invalid && (studentForm.controls['skills'].controls[skillName].dirty ||
studentForm.controls ['skills']。controls [skillName] .touched)“ class =“ alert alert-danger”> 技能名称为必填项。
validation is not working
ERROR TypeError: Cannot read property 'invalid' of undefined
can any one help
答案 0 :(得分:2)
我猜你忘了用引号将studentForm.controls['skills'].controls[skillName]
\/
['skillName']
包裹起来
{{1}}