错误:“AbstractControl”类型缺少“FormGroup”类型中的以下属性:controls、registerControl、addControl、removeControl、

VR7*_*VR7 2 angular angular-abstract-control

我使用 android 制作了一个天气 API Web 应用程序,

链接:- https://stackblitz.com/edit/maximlweatherapp

应用程序网址:- https://maximlweatherapp.stackblitz.io

我在我的 Visual Studio 代码中使用了相同的代码,它运行良好,没有出现任何错误,但在 StackBlitz 中,它出现了错误两者的唯一区别是,在我的 Visual Studio 中,安装了 Angular 版本 8,但我在这里使用 Angular 版本 9,请任何人看到代码有什么问题并建议我做一些更改,

Visual Studio Code 输出的我的工作结果 Visual Studio Code 输出的我的工作结果。

yur*_*zui 6

在 Angular 9 中默认的 AOT 模式下,模板编译器比 JIT 模式更严格。

例如,在以下代码中:

[formGroup]="checkcity.at(itemindex)"
Run Code Online (Sandbox Code Playgroud)

checkcity.at方法返回AbstractControl并且它与FormGroupDirective需要的类型不匹配。

您可以自己投射:

html

[formGroup]="getFormGroupAt(itemindex)"
Run Code Online (Sandbox Code Playgroud)

ts

getFormGroupAt(i: number) {
  return this.checkcity.at(i) as FormGroup;
}
Run Code Online (Sandbox Code Playgroud)

分叉的堆栈闪电战

或在您使用的每个地方使用内置的$any()函数checkcity.at(itemindex)

$any(checkcity.at(itemindex))
Run Code Online (Sandbox Code Playgroud)