Angular-元素隐式具有';任何';因为类型';抽象控制&x27;没有索引签名

Angular-元素隐式具有';任何';因为类型';抽象控制&x27;没有索引签名,angular,Angular,在Angular-11中,我在typescript中有以下代码: multistep = new FormGroup({ userDetails: new FormGroup({ first_name: new FormControl(''), last_name: new FormControl(''), other_name: new FormControl(''), email: new FormControl('

在Angular-11中,我在typescript中有以下代码:

multistep = new FormGroup({
      userDetails: new FormGroup({
        first_name: new FormControl(''),
        last_name: new FormControl(''),
        other_name: new FormControl(''),
        email: new FormControl(''),
        mobile_number: new FormControl(''),
        gender: new FormControl(''),
        marital_status: new FormControl(''),
        employee_photo: new FormControl('')
      })
});

get userDetails(){
   return this.multistep.controls['userDetails']['controls'];
 }
但我有一个错误:

元素隐式具有“any”类型,因为类型“AbstractControl”没有索引签名。你是想打电话给“get”吗

这是突出的:

this.multistep.controls['userDetails']['controls']

我如何解决它


谢谢

您可以改用这个:

this.multistep.get('userDetails').controls

get方法是访问formGroup中控件的方法

您可以使用以下方法:

this.multistep.get('userDetails').controls

get方法是访问formGroup中控件的方法

您需要将userDetails强制转换为formGroup
userDetails作为formGroup

  get userDetails(){
    return (this.multistep.controls.userDetails as FormGroup).controls;
  }

您需要将userDetails强制转换为FormGroup
userDetails作为FormGroup

  get userDetails(){
    return (this.multistep.controls.userDetails as FormGroup).controls;
  }

错误是告诉您如何解决该问题。不要使用括号语法,而是使用:
this.multistep.get('userDetails')作为FormGroup
错误告诉您如何解决此问题。不要使用括号语法,而是使用:
this.multistep.get('userDetails')作为FormGroup