Reputation: 1059
How do I pre-populate an Ionic 2 ion-input field?
I tried doing the below but the field remained blank.
<ion-input type="text" [(ngModel)]="product.content" name="content" value="123" required></ion-input>
Upvotes: 2
Views: 2513
Reputation: 65920
You can do it as shown below.
Working Plunk is here.
.ts
product:any= {};
constructor(public navController: NavController) {
this.product.content='123';
}
Note: Don't use any
. Always use type
with the TS
. I just showed simple demo here.
.html
<ion-input type="text" [(ngModel)]="product.content" name="content"
required></ion-input>
Upvotes: 5