如何在离子2输入中设置默认值?

时间:2017-11-29 15:23:48

标签: android angular ionic2

我想在离子输入中设置默认值..请帮助

address.html文件代码

<ion-item>
<ion-label floating>{{'address.email'|translate}}</ion-label>
        <ion-input type="text" formControlName="user_email"></ion-input>
    </ion-item>

default mail like example@gmail.com

adderss.ts

    ionViewDidEnter() {
    if (this.isCache) this.getData();
    else this.isCache = true;
}
getData() {
    this.storageMul.get(['login', 'useBilling', 'user']).then(val => {
        if (val['login']) this.login = val['login'];
        if (val['useBilling'] == false) this.useBilling = false;
        else this.useBilling = true;
        if (val['user']) {
            this.data = val['user'];

        }
        this.reset();
    });
}
reset() {
    this.formAddress.patchValue({
        billing_first_name: this.data["billing_first_name"],
        billing_address_1: this.data["billing_address_1"],
        billing_phone: this.data["billing_phone"],
        user_email: this.data["user_email"],
        shipping_first_name: this.data["shipping_first_name"],
        shipping_address_1: this.data["shipping_address_1"],
    });

请帮帮我!!

2 个答案:

答案 0 :(得分:3)

您可以使用正常[(ngModel)]绑定执行此操作。

<ion-label floating>{{'address.email'|translate}}</ion-label>
    <ion-input type="text" [(ngModel)]="user_email"></ion-input>
</ion-item>

在TypeScript中,您可以在页面加载时将变量设置为特定值

*。component.ts

constructor() {
    this.user_email = 'some@value.com';
}

这样,当用户进入屏幕时,该值将是默认值,并且仍然允许用户更新该值。

答案 1 :(得分:0)

您正在寻找&#34;占位符&#34;。

Checked= !Checked

https://ionicframework.com/docs/api/components/input/Input/

相关问题