美文网首页
Angular: Can't bind to 'ngModel'

Angular: Can't bind to 'ngModel'

作者: gstorm | 来源:发表于2021-01-05 14:21 被阅读0次

原因:
html代码中出现类似这样的<input type=“text” [(ngModel)]=“username”>语句,其中使用了[(ngModel)]。
在AngularJS2或以上版本中使用了NgModel指令,必须在app.module.ts文件中导入FormsModule模块。

解决方法:
1 . 在app.module.ts文件导入语句中添加

import { FormsModule } from ‘@angular/forms’;

2 . 修改app.module.ts文件

@NgModule({
    imports: [
         ...
         FormsModule   //此代码仅为需加入的部分,注意比对你本身的代码,把这个加入其中即可   
         ...
    ]

相关文章

网友评论

      本文标题:Angular: Can't bind to 'ngModel'

      本文链接:https://www.haomeiwen.com/subject/foaioktx.html