我使用的是Angular 4,我在控制台得到了一个错误:
不能绑定到ngModel,因为它不是input的已知属性
我该如何解决这个问题?
我使用的是Angular 4,我在控制台得到了一个错误:
不能绑定到ngModel,因为它不是input的已知属性
我该如何解决这个问题?
当前回答
在我的情况下,我拼写错误,我是指ngmodel而不是ngmodel:)希望它有帮助!
Expected - [(ngModel)] Actual - [(ngmodel)]
其他回答
首先导入FormsModule,然后在component.ts中使用ngModel
import { FormsModule } from '@angular/forms';
@NgModule({
imports: [
FormsModule
];
HTML代码:
<input type='text' [(ngModel)] ="usertext" />
我在用Karma/Jasmine测试Angular 6应用时遇到了这个错误。我已经在顶层模块中导入了FormsModule。但是当我添加一个使用[(ngModel)]的新组件时,我的测试开始失败。在这种情况下,我需要在我的TestBed TestingModule中导入FormsModule。
beforeEach(async(() => {
TestBed.configureTestingModule({
imports: [
FormsModule
],
declarations: [
RegisterComponent
]
})
.compileComponents();
}));
在我的情况下,我拼写错误,我是指ngmodel而不是ngmodel:)希望它有帮助!
Expected - [(ngModel)] Actual - [(ngmodel)]
在我的例子中,我添加了缺失的导入,即ReactiveFormsModule。
我尝试了上面提到的所有方法,但仍然不起作用。
但最后我在Angular站点上发现了这个问题。尝试在module中导入formModule。就是这样。