Moving to strict.
Create form has now moved to constructor and route data subscribe is type safe.
This commit is contained in:
@@ -46,47 +46,43 @@ export class EmployeeAttendanceComponent implements OnInit, AfterViewInit {
|
||||
private ser: EmployeeAttendanceService,
|
||||
private employeeSer: EmployeeService,
|
||||
) {
|
||||
this.createForm();
|
||||
this.listenToEmployeeValueChanges();
|
||||
}
|
||||
|
||||
ngOnInit() {
|
||||
this.route.data.subscribe(
|
||||
(data: { info: EmployeeAttendance; attendanceTypes: AttendanceType[] }) => {
|
||||
this.info = data.info;
|
||||
this.attendanceTypes = data.attendanceTypes;
|
||||
this.form.get('startDate').setValue(moment(this.info.startDate, 'DD-MMM-YYYY').toDate());
|
||||
this.form.get('finishDate').setValue(moment(this.info.finishDate, 'DD-MMM-YYYY').toDate());
|
||||
this.form.get('employee').setValue(this.info.employee);
|
||||
this.form.setControl(
|
||||
'attendances',
|
||||
this.fb.array(
|
||||
this.info.body.map((x) =>
|
||||
this.fb.group({
|
||||
attendanceType: x.attendanceType.id,
|
||||
}),
|
||||
),
|
||||
),
|
||||
);
|
||||
this.dataSource = new EmployeeAttendanceDataSource(this.employeeAttendanceObservable);
|
||||
this.employeeAttendanceObservable.next(this.info.body);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
ngAfterViewInit() {
|
||||
setTimeout(() => {
|
||||
this.employeeElement.nativeElement.focus();
|
||||
}, 0);
|
||||
}
|
||||
|
||||
createForm() {
|
||||
this.form = this.fb.group({
|
||||
startDate: '',
|
||||
finishDate: '',
|
||||
employee: '',
|
||||
attendances: this.fb.array([]),
|
||||
});
|
||||
this.listenToEmployeeValueChanges();
|
||||
}
|
||||
|
||||
ngOnInit() {
|
||||
this.route.data.subscribe((value) => {
|
||||
const data = value as { info: EmployeeAttendance; attendanceTypes: AttendanceType[] };
|
||||
|
||||
this.info = data.info;
|
||||
this.attendanceTypes = data.attendanceTypes;
|
||||
this.form.get('startDate').setValue(moment(this.info.startDate, 'DD-MMM-YYYY').toDate());
|
||||
this.form.get('finishDate').setValue(moment(this.info.finishDate, 'DD-MMM-YYYY').toDate());
|
||||
this.form.get('employee').setValue(this.info.employee);
|
||||
this.form.setControl(
|
||||
'attendances',
|
||||
this.fb.array(
|
||||
this.info.body.map((x) =>
|
||||
this.fb.group({
|
||||
attendanceType: x.attendanceType.id,
|
||||
}),
|
||||
),
|
||||
),
|
||||
);
|
||||
this.dataSource = new EmployeeAttendanceDataSource(this.employeeAttendanceObservable);
|
||||
this.employeeAttendanceObservable.next(this.info.body);
|
||||
});
|
||||
}
|
||||
|
||||
ngAfterViewInit() {
|
||||
setTimeout(() => {
|
||||
this.employeeElement.nativeElement.focus();
|
||||
}, 0);
|
||||
}
|
||||
|
||||
listenToEmployeeValueChanges() {
|
||||
|
||||
Reference in New Issue
Block a user