首页 > 解决方案 > 未捕获的错误:无法绑定到“FormGroup”,因为它不是“form”的已知属性

问题描述

我是角度的新手,尝试了堆栈溢出建议的所有可能方法,但到目前为止还没有成功。FormGroup 没有约束力。我已经在 app.module.ts 和 *.component.ts 中添加了 ReactiveFormsModule。我一直在使用 Angular 8.x

细节:

            Package                           Version
            -----------------------------------------------------------
            @angular/animations               8.2.7
            @angular/cdk                      8.2.0
            @angular/cli                      8.3.4
            @angular/forms                    8.2.7
            @angular/http                     7.2.15
            @angular/material                 8.2.0
            @angular/router                   8.2.7
            @ngtools/webpack                  8.3.4
            @schematics/angular               8.3.4
            @schematics/update                0.803.4
            rxjs                              6.4.0
            typescript                        3.5.3
            webpack                           4.39.2

=======================

组件 html 文件

<div class="container">
              <div class="row">
                <div class="profile">
                  <form [FormGroup]="catCreate" class="example-form">

========================================

创建-category.component.ts

       import { Component, OnInit } from '@angular/core';
       import { FormGroup, FormBuilder, Validators, FormControl, ReactiveFormsModule } from '@angular/forms';

            @Component({
              templateUrl: './create-category.component.html', ...
            })

            export class CreateCategoryComponent implements OnInit {
              catCreate: FormGroup; ...

=================================

app.module.ts

            import { BrowserModule } from '@angular/platform-browser';
            import { NgModule } from '@angular/core';
            import { AppRoutingModule } from './app-routing.module';
            import { AppComponent } from './app.component';
            import { CreateCategoryComponent } from './components/create-category/create-category.component';
            import { FormsModule, ReactiveFormsModule } from '@angular/forms';
            import { MaterialsModule } from './material-module';

            @NgModule({
              declarations: [
                AppComponent,
                UploaderComponent,
                CreateCategoryComponent
              ],
              imports: [
                MaterialsModule,
                FormsModule,
                ReactiveFormsModule,
                .......
    Error: Compiler.js:2175 Uncaught Error: Template parse errors:
        Can't bind to 'FormGroup' since it isn't a known property of 'form'. ("a">
       <form [ERROR ->][FormGroup]="catCreate" class="example-form">
                                 ng:///AppModule/CreateCategoryComponent.html@8:30

标签: angular8formgroups

解决方案


您需要将其绑定到小驼峰式:[formGroup] 而不是 [FormGroup]。


推荐阅读