angular8 - 未捕获的错误:无法绑定到“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
解决方案
您需要将其绑定到小驼峰式:[formGroup] 而不是 [FormGroup]。
推荐阅读
- c# - 使用 itext7 填充 pdf 表单时调用 FillXfaForm 后,XML 数据集在 xfa.datasetsNode 中重复
- sql - 在 SQL 中为每个 id 引用添加列
- facebook - Facebook 显示页面帖子的权限
- shell - api curl脚本没有给出输出
- flutter - 如何修复 Flutter MaterialApp(not_enough_required_arguments)?
- javascript - 通过 HTML 文件输入上传 PSD/任何 Photoshop 文件不起作用
- mysql - 使用多唯一键插入重复键更新sql时出现死锁
- mysql - 使用内部联接表进行高级搜索
- html - 当两个元素向右浮动时,它们会切换位置
- kubernetes - 设置 Kubernetes - 无法从 Pod 访问 API