【发布时间】:2021-08-24 16:44:10
【问题描述】:
在我的 Angular-11 中,我的打字稿中有这段代码:
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'];
}
但是我收到了这个错误:
元素隐含地具有“任何”类型,因为类型“AbstractControl”没有索引签名。您的意思是调用“get”吗?
这是突出显示的:
this.multistep.controls['userDetails']['controls'];
如何解决?
谢谢
【问题讨论】:
-
错误告诉您如何解决问题。不要使用括号语法,而是使用:
this.multistep.get('userDetails') as FormGroup
标签: angular