离子4 - 离子输入双向结合

Ka *_*ech 3 ionic-framework ionic4

在Ionic 4中你如何进行双向绑定.在Ionic 3中,我会做以下事情:

<ion-item color="light"> <ion-input type="string" placeholder="Username" [(ngModel)]="username"></ion-input> </ion-item>
Run Code Online (Sandbox Code Playgroud)

但是在Ionic 4中我收到以下错误:

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. ("d>
          <ion-item color="light">
              <ion-input type="string" placeholder="Username" [ERROR ->][(ngModel)]="username"></ion-input>
          </ion-item>
          <ion-item color="light">
"): ng:///AppModule/LoginPage.html@12:62
Run Code Online (Sandbox Code Playgroud)

我如何在Ionic 4中使用它?

小智 9

请记住将FormsModule添加到模块或创建SharedModule以导入和导出FormsModule

@NgModule({
  imports: [
    CommonModule,
    FormsModule,
    IonicModule,
    RouterModule.forChild([
      {
        path: '',
        component: HomePage
      }
    ])
  ],
  declarations: [HomePage]
})
export class HomePageModule { }
Run Code Online (Sandbox Code Playgroud)