How to clear the form after submitting in model-driven form? (Angular 2) -
how can clear form after submitting in model-driven form? have use ngmodel
? thanks
<form [ngformmodel]="myform" (ngsubmit)="onsubmit()"> <input type="text" [ngformcontrol]="name"> <button type="submit">submit</button> </form>
.
myform: controlgroup; name: abstractcontrol; ngoninit() { this.myform = this._formbuilder.group({ 'name': [""] }); this.name = this.myform.controls['name']; } onsubmit() { this.name.value = ""; // not working. }
you can iterate controls in this.myform.controls
, call updatevalue()
. otherwise see https://github.com/angular/angular/issues/4933
Comments
Post a Comment