简体   繁体   English

无法绑定到'FormGroup',因为它不是'form'的已知属性----

[英]Can't bind to 'FormGroup' since it isn't a known property of 'form' ----

So i've been looking through internet and everyone says the same thing and that is i have to add imports in appmodule.ts but i've added imports and i still have the same error. 所以我一直在浏览互联网,每个人都说同样的事情,这是我必须在appmodule.ts添加导入,但我已经添加了导入,我仍然有相同的错误。

The error is: 错误是:

Can't bind to 'FormGroup' since it isn't a known property of 'form'. ("
        <ion-col>

            <form novalidate [ERROR ->][FormGroup]="form" (ngSubmit)="addUser(form)">

                <ion-title class="center">Registr"): ng:///AppModule/RegisterPage.html@8:33

Register.html ( https://ghostbin.com/paste/8wn3q ) Register.html( https://ghostbin.com/paste/8wn3q

Register.ts ( https://ghostbin.com/paste/3sxcz ) Register.ts( https://ghostbin.com/paste/3sxcz

Appmodule.ts ( https://ghostbin.com/paste/wgmxd ) Appmodule.ts( https://ghostbin.com/paste/wgmxd

It looks like you're using Ionic4? 看起来你正在使用Ionic4? You also need to import FormsModule and ReactiveFormsModule into your <page-name>.module.ts and then add them to the imports array. 您还需要将FormsModuleReactiveFormsModule导入<page-name>.module.ts ,然后将它们添加到imports数组中。

[FormGroup] should be [formGroup] . [FormGroup]应为[formGroup]

Notice the lowercase f . 注意小写字母f

Also another common culprit when you face this issue is lazy loading. 当你遇到这个问题时,另一个常见的罪魁祸首是延迟加载。 If you are lazy loading don't forget to include the relevant imports(in this case ReactiveFormsModule) in current module not just in the parent module. 如果您是延迟加载,请不要忘记在当前模块中包含相关导入(在本例中为ReactiveFormsModule),而不仅仅是在父模块中。

Looks like you confused two ways of Angular forms usage - you should use directive in template, and class instance in component file: 看起来你混淆了Angular表单的两种使用方式 - 你应该在模板中使用指令 ,在组件文件中使用实例:

  1. Use directive in templates, it should be camelCase , as described here: https://angular.io/guide/reactive-forms#step-2-associating-the-formgroup-model-and-view 在模板中使用指令,它应该是camelCase ,如下所述: https//angular.io/guide/reactive-forms#step-2-associating-the-formgroup-model-and-view

     <form [formGroup]="yourFormName"> CONTENT </form> 
  2. Use constructor in components, it should start from UpperCase letter (as any class name), as described here: https://angular.io/guide/reactive-forms#step-1-creating-a-formgroup-instance 在组件中使用构造函数,它应该从UpperCase字母(作为任何类名)开始,如下所述: https//angular.io/guide/reactive-forms#step-1-creating-a-formgroup-instance

     export class YourComponent { public yourFormName: FormGroup = new FormGroup({ firstControl: new FormControl(''), lastControl: new FormControl(''), }); } 

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 无法绑定到“ FormGroup”,因为它不是“ form”的已知属性。 (” - Can't bind to 'FormGroup' since it isn't a known property of 'form'. (" 无法绑定到“formGroup”,因为它不是“form”的已知属性 - Can't bind to 'formGroup' since it isn't a known property of 'form' 无法绑定到“formGroup”,因为它不是已知的本机属性 - Can't bind to 'formGroup' since it isn't a known native property 无法绑定到 formGroup,因为它不是“表单”的已知属性 - Cant bind to formGroup since it isn't a known property of 'form' Angular 6:无法绑定到“FormGroup”,因为它不是“form”的已知属性 - Angular 6: Can't bind to 'FormGroup' since it isn't a known property of 'form' 未捕获的错误:模板解析错误:无法绑定到“ FormGroup”,因为它不是“ form”的已知属性 - Uncaught Error: Template parse errors: Can't bind to 'FormGroup' since it isn't a known property of 'form' 模板解析错误:无法绑定到“ formGroup”,因为它不是“ form”的已知属性 - Template parse errors: Can't bind to 'formGroup' since it isn't a known property of 'form' 无法绑定到“ formGroup”,因为它不是“ form”的已知属性-Angular 8 Ionic 4 - Can't bind to 'formGroup' since it isn't known property of 'form' - Angular 8 Ionic 4 无法绑定到“ formGroup”,因为它不是角度7中“ form”的已知属性 - Can't bind to 'formGroup' since it isn't a known property of 'form' in angular 7 Angular 10 - 无法绑定到“formGroup”,因为它不是“form”的已知属性 - Angular 10 - can't bind to 'formGroup' since it isn't a known property of 'form'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM