ionic-framework - Ionic 4 - 离子输入双向绑定
问题描述
在 Ionic 4 中,您如何进行双向绑定。在 Ionic 3 中,我会执行以下操作:
<ion-item color="light"> <ion-input type="string" placeholder="Username" [(ngModel)]="username"></ion-input> </ion-item>
但是在 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
我如何让它在 Ionic 4 中工作?
解决方案
请记住将 FormsModule 添加到您的模块或创建 SharedModule 以导入和导出 FormsModule
@NgModule({
imports: [
CommonModule,
FormsModule,
IonicModule,
RouterModule.forChild([
{
path: '',
component: HomePage
}
])
],
declarations: [HomePage]
})
export class HomePageModule { }
推荐阅读
- android - 如何生成室内地图?
- python - 大数据集python组合计算的优化方法
- directory - XCOPY 或 ROBOCOPY:如何将整个嵌套子文件夹复制到另一个磁盘上的更高级别?
- python - PyCharm 如何查找使用 pip 安装的库
- node.js - discord.js client.off 失败
- angular - 可以为多个服务器地址配置代理吗?
- python - 如何通过python连接到MariaDB?
- vuejs3 - Inertia.reload() 不加载超过 1 个组件
- docker - Docker Swarm 安全最佳实践
- javascript - 使用 JQuery null 从 Ajax 提交滑块值