I have a component which is used for route navigation without component reload:
export class TableComponent extends SafeComponent implements OnInit {
customersMe$: Observable<ICompanyCustomer>;
customersMe: ICompanyCustomer;
tables$: Observable<ITable[]>;
headersLoaded$: Observable<boolean>;
headerLoading = true;
table: ITable;
TableForm: FormGroup;
constructor(
private store: Store<State>,
private router: Router,
private route:ActivatedRoute,
private changeDetectorRef: ChangeDetectorRef,
) {
super();
}
ngOnInit(): void {
this.tables$ = this.store.pipe(select(getTables));
this.headersLoaded$ = this.store.pipe(select(getLoaded));
combineLatest([this.tables$, this.headersLoaded$, this.route.params])
.subscribe(([tables, loaded, params]) => {
if (loaded) {
this.headerLoading = false;
const table = tables.find(x => x.id === Number(params['id']));
if (table) {
this.table = table;
} else {
// navigate 404
}
this.changeDetectorRef.detectChanges();
}
})
/* this.tableForm = new FormGroup({
* start: new FormControl(this.table.time_start),
* end: new FormControl(this.table.time_finish)
*});*/
}
}
As you notice here I subscribe to route and update data on new id in route path. How can I update data in Form Group? Thank you!
this.form.patchValue({ name: 'Todd Motto', event: { title: 'AngularCamp 2016', location: 'Barcelona, Spain' } });