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

前端 未结 30 1022
予麋鹿
予麋鹿 2020-11-22 12:44

I\'ve got the following error when launching my Angular app, even if the component is not displayed.

I have to comment out the so that my

30条回答
  •  北海茫月
    2020-11-22 13:18

    ngModel is coming from FormsModule.There are some cases when you can receive this kind of error:

    1. You didn't import the FormsModule into import array of module where your component is declared, component in which the ngModel is used.
    2. You have import the FormsModule into one module which is inherited of another module. In this case you have two options:
      • let the FormsModule imported into the import array from both modules:module1 and module2. As rule: Importing a module does NOT provide access to its imported modules.(Imports are not inherited)

    • declare the FormsModule into the import and export arrays in module1 to be abble to see it in model2 also

    1. (In some version I faced this problem) You have imported correctly the FormsModule but the problem is on the input HTML tag. You must add the name tag attribute for input and the object bound name in [(ngModel)] must be the same as the name into the name attribute

提交回复
热议问题