For example, I created an input field using following code:
<form [formGroup]="orderForm" (ngSubmit)="submit();">
<ion-list>
<ion-item>
<ion-label >Item Name:</ion-label>
<ion-input type="text" formControlName="itemname" clearInput></ion-input>
</ion-item>
</ion-list>
<button ion-button type="submit" [disabled]="!orderForm.valid">Submit</button>
</form>
And the “ts” file like this to handle the validation and show the submitted result on the console:
public orderForm:any;
constructor(private formBuilder: FormBuilder){
//constructor(formBuilder){
this.orderForm = this.formBuilder.group({
"itemname":["",Validators.required]
//"address": ["",Validators.required]
});
}
submit() {
console.log(this.orderForm.value);
}
But how can I clear the value on the input filed after clicked the submit button? Please help and thanks!!!