I have used Angular Material & Reactive Forms. First I am taking the system date & showing it. But when I click submit it gives null value. Below are both HTML & TS Part.
<form [formGroup]="atAdminName" (ngSubmit)="onFormSubmit()">
<div class="row">
<div class="col-md-6">
<label style="font-size: 18px">
From :
</label>
<mat-form-field>
<input matInput [matDatepicker]="picker1" formControlName="date1" [formControl]="date" style="font-size:18px">
<mat-datepicker-toggle matSuffix [for]="picker1"></mat-datepicker-toggle>
<mat-datepicker #picker1></mat-datepicker>
</mat-form-field>
<br>
</div>
</div>
<div class="text-center">
<button type="submit" class="btn btn-primary">Show Report</button>
<button type="button" class="btn btn-default waves-effect">Reset</button>
</div>
</form>
And below is TS
export class AdminNameComponent implements OnInit {
atAdminName = new FormGroup({
date1: new FormControl()
});
get date1() { return this.atAdminName.get('date1'); }
date = new FormControl(new Date());
serializedDate = new FormControl((new Date()).toISOString());
constructor(private fb: FormBuilder, public usr?: UserService) {
this.atAdminName = this.fb.group({
date1: new FormControl('', Validators.required),
})
}
onFormSubmit() {
const userid = this.usr.getUserId();
console.log(this.atAdminName.value);
}
}