我使用的是Angular 4,我在控制台得到了一个错误:
不能绑定到ngModel,因为它不是input的已知属性
我该如何解决这个问题?
我使用的是Angular 4,我在控制台得到了一个错误:
不能绑定到ngModel,因为它不是input的已知属性
我该如何解决这个问题?
当前回答
如果在导入formsmodule之后问题仍然存在,请检查Input是否具有“name”属性,其值等于页面上的另一个输入。
其他回答
用Angular 7.x更新。X,在我的一个模块中遇到了同样的问题。
如果它在你的独立模块中,添加这些额外的模块:
import { CommonModule } from "@angular/common";
import { FormsModule } from "@angular/forms";
@NgModule({
imports: [CommonModule, FormsModule], // the order can be random now;
...
})
如果它在app。module中。Ts,添加这些模块:
import { BrowserModule } from '@angular/platform-browser';
import { FormsModule } from '@angular/forms';
@NgModule({
imports: [ FormsModule, BrowserModule ], // order can be random now
...
})
一个简单的演示来证明这一点。
我尝试了上面提到的所有方法,但仍然不起作用。
但最后我在Angular站点上发现了这个问题。尝试在module中导入formModule。就是这样。
在花了几个小时在这个问题上找到解决方案
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
@NgModule({
imports: [
FormsModule,
ReactiveFormsModule
]
})
如果在导入formsmodule之后问题仍然存在,请检查Input是否具有“name”属性,其值等于页面上的另一个输入。
在我的例子中,我添加了缺失的导入,即ReactiveFormsModule。