错误TypeError:无法读取未定义的属性“无效”

时间:2019-02-02 10:57:56

标签: angular

  1. 我正在使用嵌套的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
    

1 个答案:

答案 0 :(得分:2)

我猜你忘了用引号将studentForm.controls['skills'].controls[skillName] \/ ['skillName'] 包裹起来

{{1}}
相关问题