How to clear form inside of dialog material angular 2

Viewed 4620

I have a dialog created on angular 2 material. I'm opening the modal as follows:

my component

....
private refDialog;
@ViewChild('display') display;

openDialog() {
    this.refDialog= this.dialog.open(this.display);
}
....

my html

<ng-template #display>
    <form (ngSubmit)="onSubmit(f)" #f="ngForm">
        <div class='col-md-12'>
            <md-input-container>
                <input mdInput placeholder="Name" name="name" [(ngModel)]="product.name" #name="ngModel">
            </md-input-container>
        </div>

        .....

    </form>
</ng-template>

I need to clear the form before opening the dialog. I would like to do this as simply as possible. I was using the primeNG dialog and with it I used this.f.reset (); And it worked. But the angular material 2 work differently.

I tried everything without success. This does not work for me:

....
private refDialog;
@ViewChild('display') display;
@ViewChild('f') f;

openDialog() {
    this.f.reset();
    this.refDialog= this.dialog.open(this.display);
}

....

can anybody help me?

1 Answers
Related