我想在离子输入中设置默认值。.请帮助
地址.html文件代码
<ion-item>
<ion-label floating>{{'address.email'|translate}}</ion-label>
<ion-input type="text" formControlName="user_email"></ion-input>
</ion-item>
默认邮件如示例@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"],
});
请帮助我!
您将使用普通的[(ngModel)]
绑定来执行此操作。
<ion-label floating>{{'address.email'|translate}}</ion-label>
<ion-input type="text" [(ngModel)]="user_email"></ion-input>
</ion-item>
在您的打字稿中,您将变量设置为特定值,当时该页面加载
*。component.ts
constructor() {
this.user_email = 'some@value.com';
}
用户输入屏幕时,该值将是默认值,并且仍然允许用户更新该值。
您正在寻找"占位符"。
<ion-input placeholder="email@place.com"></ion-input>
https://ionicframework.com/docs/api/components/input/input/