FormControl 类型的角度打字稿 [英] FormControl type angular typescript

查看:28
本文介绍了FormControl 类型的角度打字稿的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这样的东西

 get formControls(): any {返回 this.form.controls;}

但是现在我遇到了 tslint 的问题.它返回错误'any' 的类型声明失去了类型安全性.考虑用更精确的类型替换它.有人知道 this.form.controls 返回什么类型吗?我尝试过 FormGroupFormControl,但没有一个是正确的.

解决方案

 get formControls(): { [key: string]: AbstractControl } {返回 this.form.controls;}

<块引用>

子控件的集合.每个孩子的关键是名字在其下注册.

https://angular.io/api/forms/FormGroup#controls

I have something like this

  get formControls(): any {
    return this.form.controls;
  }

But now I have a problem with tslint. It returns the error Type declaration of 'any' loses type-safety. Consider replacing it with a more precise type. Does anybody knows what type does this.form.controls return? I have tried FormGroup, FormControl, but none was correct.

解决方案

  get formControls(): { [key: string]: AbstractControl } {
    return this.form.controls;
  }

A collection of child controls. The key for each child is the name under which it is registered.

https://angular.io/api/forms/FormGroup#controls

这篇关于FormControl 类型的角度打字稿的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆