无法绑定到“NgModel”,因为它不是“离子输入”的已知属性

M. *_*cal 8 ionic3 angular

我不知道如何处理这个错误:

Error: Uncaught (in promise): Error: Template parse errors:
Can't bind to 'NgModel' since it isn't a known property of 'ion-input'.
1. If 'ion-input' is an Angular component and it has 'NgModel' input, then verify that it is part of this module.
2. If 'ion-input' is a Web Component then add 'CUSTOM_ELEMENTS_SCHEMA' to the '@NgModule.schemas' of this component to suppress this message.
3. To allow any property add 'NO_ERRORS_SCHEMA' to the '@NgModule.schemas' of this component. ("
<ion-item>
  <ion-label>Cambio</ion-label>
  <ion-input type="text" [ERROR ->][(NgModel)]="item.cambio" placeholder="e.g:"></ion-input>
</ion-item>
Run Code Online (Sandbox Code Playgroud)

关于进口,我也有这个代码:

 imports: [
    ...,
    IonicModule.forRoot(MyApp),
    ...
Run Code Online (Sandbox Code Playgroud)

我正在Udemy 上学习这门课程,但没有关于此问题的任何信息

Awa*_*sir 17

如果您正在使用[(ngModel)]并且仍然收到此错误,请不要忘记FormsModule在当前模块中导入

  • 除了问题是关于属性输入错误之外,对于使用 ionic 4+(使用新版本 Angular)的用户来说,这是正确的答案! (4认同)

Sid*_*era 7

您正在使用:

[(NgModel)]="item.cambio"
Run Code Online (Sandbox Code Playgroud)

什么时候应该使用:

[(ngModel)]="item.cambio"
Run Code Online (Sandbox Code Playgroud)

像这样更改模板代码:

<ion-item>
  <ion-label>Cambio</ion-label>
  <ion-input type="text" [(ngModel)]="item.cambio" placeholder="e.g:"></ion-input>
</ion-item>
Run Code Online (Sandbox Code Playgroud)