如何修复 Angular 'Cannot find control with unspecified name attribute'

问题:

在你的 Angular2/4/5 应用程序中你看到此错误消息:

angular_error.txt
Cannot find control with unspecified name attribute

解决方案

在 HTML angular 模板中查找类似这样的语句:

template_example.html
[formControl]="myCtrl"

错误消息表示找不到 myCtrl。检查此变量是否存在于你的类中 - 它需要是 FormControl,你可以从 @angular/forms import

import_formcontrol.ts
import { FormControl } from '@angular/forms';

在我的情况下,将其更改为

template_fixed.html
[formControl]="myControl"

修复了问题


Check out similar posts by category: Angular, Javascript, Typescript