![](/img/trans.png)
[英]Why is form: FormGroup showing 'controls' as undefined in an Angular11 component?
[英]Problem when binding to 'formGroup' on Angular11
我正在为家庭作业开发一个 Angular11 项目,并且我正在尝试使用一些引导程序将数据保存到我的 Cloud Firestore 中,但是当我启动该应用程序时,它会显示以下内容:
错误 NG8002:无法绑定到“formGroup”,因为它不是“form”的已知属性。
<form class="mt-4" [formGroup]="createProducto" (ngSubmit)="agregarProducto()">
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src/app/components/add-productos.component.ts:9:16
9 templateUrl: '../views/add-productos.component.html',
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Error occurs in the template of component AddProductosComponent.
这是我遇到问题的地方
<form class="mt-4" [formGroup]="createProducto" (ngSubmit)="agregarProducto()">
这是我对组件的导入:
import { FormBuilder, FormGroup, Validators } from '@angular/forms';
import { ProductoService } from '../services/producto.service'
import { Router, ActivatedRoute } from '@angular/router';
import { ToastrService } from 'ngx-toastr';
这是我创建“createProducto:FormGroup”m 的地方,它应该可以正常工作
export class AddProductosComponent implements OnInit {
createProducto: FormGroup
submitted = false
我已经尝试过人们在这里发布的一些东西,但它们都不适合我。
我通过在我的 AddProductosComponent 中导入 ReactiveFormsModule、FormsModule 来修复错误。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.