gpt4 book ai didi

ionic-framework - Ionic 4 - ionic 输入双向绑定(bind)

转载 作者:行者123 更新时间:2023-12-04 16:38:12 24 4
gpt4 key购买 nike

在 Ionic 4 中,您如何进行双向绑定(bind)。在 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 中工作?

最佳答案

带角度 6 的 ionic 3/4

为了能够对表单输入使用双向数据绑定(bind),您需要在 Angular 模块中导入 FormsModule 包。更多信息参见 Angular 官方教程 here

例如

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

[...]

@NgModule({
imports: [
[...]
FormsModule
],
[...]
})

关于ionic-framework - Ionic 4 - ionic 输入双向绑定(bind),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52304368/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com