given following paths:
const appRoutes: Routes = [
{ path: '', component: ListComponent },
{ path: 'items/:id', component: ItemOutletComponent,
children:[
{ path: '', component: Section1Component },
{ path: 'page2', component: Section2Component, },
]
}];
how to ensure that a custom method called applyChanges()
on Section1Component
, resp Section2Component
each time:
- user navigates away from the page
- the
:id
url parameter changes - as a bonus question, also when user closes the browser?
I currently load resource model in ItemOutletComponent
, I create FormGroup on each section component:
ngOnInit() {
this.formGroup = new FormGroup({
section1: new FormGroup({
prop1: new FormControl(),
prop2: new FormControl()
});
this.formGroup.pathValue(this.model);
}
applyChanges() {
Object.assign(this.model, this.formGroup.value);
}
All I need is to ensure that formGroup changes are applied back to model at appropriate time. There is no Save button on the page.