Save data from an Angular 2 component before navigate to another component -
i save angular 2 component related data database before navigating particular component component database saved data able display on second component. in order called save method on ngondestroy() hook of first component , display method on second component ngoninit().
however, looks ngoninit() calls before ngondestroy() finished. means before saving data database second component retrieve old data , displaying.
please me resolve issue.
you can implement candeactivate
purpose. router continues route change if promise
returnes routercandeactivate
resolves true
see https://angular.io/docs/ts/latest/api/#!?apifilter=candeactivate
rc.x
routercandeactivate(currtree?: routetree, futuretree?: routetree) : promise<boolean> { return new promise<boolean>((resolve, reject) => { ... }) }
beta.x or router-deprecated in rc.x
routercandeactivate(nextinstruction: componentinstruction, previnstruction: componentinstruction) { return new promise<boolean>((resolve, reject) => { ... }) }
the router-deprecated has ondeactivate
. https://angular.io/docs/ts/latest/api/router-deprecated/index/ondeactivate-interface.html. might added new router well.
Comments
Post a Comment