角度错误:“无法绑定到'ngModel',因为它不是'input'的已知属性" [英] Angular error: "Can't bind to 'ngModel' since it isn't a known property of 'input'"

查看:72
本文介绍了角度错误:“无法绑定到'ngModel',因为它不是'input'的已知属性"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Angular 4,但在控制台中出现错误:

I'm using Angular 4 and I am getting an error in the console:

由于它不是'input'的已知属性,因此无法绑定到'ngModel'

Can't bind to 'ngModel' since it isn't a known property of 'input'

我该如何解决?

推荐答案

要对表单输入使用双向数据绑定,您需要在Angular模块中导入 FormsModule 包.

In order to use two-way data binding for form inputs you need to import the FormsModule package in your Angular module.

import { FormsModule } from '@angular/forms';

@NgModule({
    imports: [
         FormsModule      
    ]


编辑

由于存在很多相同问题的重复问题,因此我正在增强此答案.

Since there are lot of duplicate questions with the same problem, I am enhancing this answer.

有两个可能的原因

  • 缺少 FormsModule ,因此将其添加到模块中,

  • Missing FormsModule, hence Add this to your Module,

import { FormsModule } from '@angular/forms';

@NgModule({
    imports: [
        FormsModule      
    ]

  • 在输入标记中检查[(ngModel)]的语法/拼写

  • Check the syntax/spelling of [(ngModel)] in the input tag

    这篇关于角度错误:“无法绑定到'ngModel',因为它不是'input'的已知属性"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

  • 查看全文
    相关文章
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆