Skip to content

Instantly share code, notes, and snippets.

@fireflysemantics
Created June 10, 2022 03:21
Show Gist options
  • Save fireflysemantics/1f8f2fd59a5993115bf99e4e41eb5a52 to your computer and use it in GitHub Desktop.
Save fireflysemantics/1f8f2fd59a5993115bf99e4e41eb5a52 to your computer and use it in GitHub Desktop.
<form (ngSubmit)="onSubmit()" [formGroup]="form">
<mat-form-field class="example-form-field" appearance="fill">
<mat-label>Name</mat-label>
<input matInput type="text" formControlName="name" />
<button
*ngIf="form.value.name"
matSuffix
mat-icon-button
aria-label="Clear"
(click)="form.controls.name.setValue('')"
>
<mat-icon>close</mat-icon>
</button>
</mat-form-field>
<mat-form-field class="example-form-field" appearance="fill">
<mat-label>Email</mat-label>
<input matInput type="text" formControlName="email" />
<button
*ngIf="form.value.email"
matSuffix
mat-icon-button
aria-label="Clear"
(click)="form.controls.email.setValue('')"
>
<mat-icon>close</mat-icon>
</button>
</mat-form-field>
<mat-form-field class="example-form-field" appearance="fill">
<mat-label>Phone</mat-label>
<input matInput type="tel" formControlName="phone" />
<button
*ngIf="form.value.phone"
matSuffix
mat-icon-button
aria-label="Clear"
(click)="form.controls.phone.setValue('')"
>
<mat-icon>close</mat-icon>
</button>
</mat-form-field>
<br />
<button mat-button type="submit">Submit</button>
<br />
<button mat-button (click)="reset()" type="reset">Reset</button>
</form>
<button mat-button (click)="removePhone()">Remove Phone Field</button>
<p [innerHTML]="data"></p>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment