I have one component under which I have modal popup which contains child component :
<modal data-backdrop="static" #modalTask (onDismiss)="modalTask.close()" [size]="'lg'">
<modal-header>
<h4 style="color:#fff">Add CRL Task</h4>
</modal-header>
<modal-body>
<TaskComponent [isReset] ="resetForm" #tasks></crlTask>
</modal-body>
<modal-footer>
<button type="button" class="btn btn-primary" (click)="onTaskClick();">Create</button>
<button type="button" class="btn btn-default" data-dismiss="modal" (click)="modalTask.close();">Cancel</button>
</modal-footer>
</modal>
Now that child component is as follows :
<form #taskForm="ngForm" name="rplForm">
//Contains Input Controls
</form>
EDIT
As got one solution I have put reset inside ngOnChanges
of child component. Here is the code from Child component
taskForm: FormGroup;
@Input() isReset: boolean = false;
ngOnChanges() {
if (this.isReset) {
this.rplForm.reset();
}
}
Now I am saving taskForm
on onTaskClick()
and I am able to do so. What I am not able to do is to resetting the form which is under child component.
I tried using reset()
but was not able to do so. Anything using which I can do so from parent component?
rplForm
istaskForm
. That was a mistake that I have updated. – Mae