首页 > 解决方案 > Angular 8:在带有按钮错误代码的表单中添加输入字段

问题描述

您好,我需要使用按钮将输入字段添加到我的表单中。这是我的代码:stackblitz 我的代码中有一些错误。我在浏览器控制台中得到了这个:Cannot find control with name: '0'并且AuditsComponent.html:9 ERROR TypeError: control.registerOnChange is not a function 在我的角度服务器中:ERROR in src/app/components/audits/audits.component.ts(50,26): error TS2345: Argument of type 'any' is not assignable to parameter of type 'never'.

感谢您的贡献!

标签: angulartypescript

解决方案


我正在更正你的代码

https://stackblitz.com/edit/angular-hfrx5u

您必须在 app.module.ts 中安装导入

  1. 棱角材料
  2. 导入一个 MatInputModule
  3. 对于反应式表单输入 ReactiveFormsModule

     import { FormsModule, ReactiveFormsModule } from '@angular/forms';
     import {MatInputModule} from '@angular/material/input';  
    
     and in NgModule
    
    imports:[ BrowserModule, FormsModule, ReactiveFormsModule, MatInputModule],
    

推荐阅读