Subscribe to data change in Angular 2 based on route navigation -
suppose have following routes:
[ { path: 'view', children: [ { path: ':id', component: customerviewcomponent, resolve: { customerviewdata: customerresolve, edit: viewrouteresolve // returns false }, data: { other: false }, children: [ { path: 'edit', resolve: { edit: editrouteresolve // returns true }, data: { other: true } }, { path: '', data: { other: false } } ] } ] }, { path: '', component: customerlistcomponent } ] i want use customerviewcomponent /view/ , /view/1/edit
the problem unable catch data change in component. have tried resolve or data , can't catch changes...
this code not trigger expected:
this.route.data.subscribe(m => { debugger; // triggers once view loads, never again }); // triggers quite often, data stale. this.router.events.subscribe(m => { console.log(this.route.snapshot.data['edit']); console.log(this.route.snapshot.data['other']); debugger; }); could bug? work around @ event navigationend , analyze .url string property...
try instead use activatedroute @angular/router
this.activatedroute.params.subscribe(params => { console.log(params['edit']); console.log(params['other']); });
Comments
Post a Comment