How to set default value in ionic input?


#1

I want to set a default value in ionic input … please help

adderss.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


#2

2 ways.

  1. set the value="example@gmail.com"
  2. use placeholder attribute on ion-input. ie. placeholder="example@gmail.com"

#3

its get from something formControlName="user_email" so value="example@gmail.com" not working … and i can not remove formControlName="user_email" … because when i try to remove this … my app not working!!!

here is my .ts code }); translate.get('address.location').subscribe(trans => this.trans = trans); this.formAddress = this.formBuilder.group({ billing_first_name: ['', Validators.required], billing_address_1: ['', Validators.required], billing_phone: ['', Validators.compose([Validators.required, CoreValidator.isPhone])],user_email: [’’],shipping_first_name: [''], shipping_address_1: [''], }); this.getData(); please tell how set defult value from user_email: [''],


#4

Dont set a value like that.
Set a value like it used to be in Ionic with NgModel

.ts file

// Define before your constructor as:
sDefaultEmail   :  string;

constructor()
{
    sDefaultEmail = 'example@gmail.com';
}

.html file

[(ngModel)]="sDefaultEmail"

#5

bind the input value with a variable and initialize it with some value
.ts file
email:string=‘default@email.com’ before the constructor of page
and bind it with ngModel

<ion-input type=“email” [(ngModel)] = “email”>

and also use input type email instead of text