Angular NG8002:Can';t绑定到';ngModel';因为它不是';t'的已知属性;输入';。角度10
我想弄清楚为什么会出现这个错误。到目前为止,阅读大量答案有两个可能的原因。缺少[(ngModel)]的FormsModule导入或语法。还是找不到我做错了什么 角度版本,以防有帮助: 角度:10.0.4 ... 动画、通用、编译器、编译器cli、核心、表单 ... 本地化、平台浏览器、平台浏览器动态、路由器 常春藤:是的Angular NG8002:Can';t绑定到';ngModel';因为它不是';t'的已知属性;输入';。角度10,angular,Angular,我想弄清楚为什么会出现这个错误。到目前为止,阅读大量答案有两个可能的原因。缺少[(ngModel)]的FormsModule导入或语法。还是找不到我做错了什么 角度版本,以防有帮助: 角度:10.0.4 ... 动画、通用、编译器、编译器cli、核心、表单 ... 本地化、平台浏览器、平台浏览器动态、路由器 常春藤:是的 Package Version ----------------------------------------------
Package Version
-----------------------------------------------------------
@angular-devkit/architect 0.1000.3
@angular-devkit/build-angular 0.1000.3
@angular-devkit/build-optimizer 0.1000.3
@angular-devkit/build-webpack 0.1000.3
@angular-devkit/core 10.0.3
@angular-devkit/schematics 10.0.3
@angular/cli 10.0.3
@ngtools/webpack 10.0.3
@schematics/angular 10.0.3
@schematics/update 0.1000.3
rxjs 6.5.5
typescript 3.9.6
webpack 4.43.0
错误:
src/app/business-info/business-info.component.ts:12:16
12 templateUrl: './business-info.component.html',
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Error occurs in the template of component BusinessInfoComponent.
src/app/business-info/business-info.component.html:497:94 - error NG8002: Can't bind to 'ngModel' since it isn't a known property of 'input'.
497 <input class="form-check-input" type="checkbox" id="terms" formControlName="terms" [(ngModel)]="termsAccept">
有人知道我遗漏了什么吗?在App.module.ts中
import { FormsModule } from '@angular/forms';
并将表单模块
包含在
imports: [
....
FormsModule
]
乍一看,你可能想考虑引进一些懒散加载的模块….. @ MikeOne真的,我会尝试实现这一点,在不久的将来,那错误呢?每当我得到这个错误,它是从一个缺少的进口,但你有这个。可能尝试删除formControlName,因为它是被动表单,而ngModel是模板驱动表单。如果不尝试,请选择是使用被动表单还是使用模板驱动表单,然后删除其中一个表单
import { FormsModule } from '@angular/forms';
imports: [
....
FormsModule
]