属性'controls'在类型'AbstractControl'表单验证Angular 7中不存在

时间:2019-04-01 10:45:45

标签: angular

我知道这类问题有很多可能的答案,但是我无法根据自己的情况解决。我正在按照本教程进行验证,但是它适用于旧的Angular版本: https://medium.freecodecamp.org/validating-reactive-forms-with-default-and-custom-form-field-validators-in-angular-5586dc51c4ae

现在我得到错误:haystack属性的import { Subscription } from 'rxjs'; export class MyComponent implements OnInit, OnDestroy { private subscription: Subscription //import from rxjs constructor(private myService: MyService){} ngOnInit() { this.subscription = this.myService.myMethod.subscribe(...); } ngOnDestroy() { this.subscription.unsubscribe(); } } 。我从教程中复制了确切的内容,只是将其重命名了。如何达到与Property 'controls' does not exist on type 'AbstractControl'相同的值?

control.controls

在我的component.ts中:

control.controls

如何进行更改以获取FormControl,而不是在此处构建我的建筑物。

版本:Angular 7

1 个答案:

答案 0 :(得分:1)

这是一个Typescript警告,告诉它如果AbstractControl不包含任何此类道具,则无用地检查controls的{​​{1}}属性(默认)。

执行此操作:

AbstractControl

在此处查看示例:https://stackblitz.com/edit/angular-nqxdrj?file=src%2Fapp%2Fapp.component.html