xxxxxxxxxx
onSubmit() {
if (this.myform.valid) {
console.log("Form Submitted!");
this.myform.reset();
}
}
xxxxxxxxxx
<input type="text" [(ngModel)]="name" required />
<button (click)="handleClear()">Clear input field</button>
xxxxxxxxxx
import { Component } from '@angular/core';
@Component({
selector: 'my-app',
templateUrl: './app.component.html',
styleUrls: [ './app.component.css' ]
})
export class AppComponent {
name = 'Angular';
handleClear(){
this.name = ' '; }
}