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

Popular posts from this blog

javascript - Laravel datatable invalid JSON response -

java - Exception in thread "main" org.springframework.context.ApplicationContextException: Unable to start embedded container; -

sql server 2008 - My Sql Code Get An Error Of Msg 245, Level 16, State 1, Line 1 Conversion failed when converting the varchar value '8:45 AM' to data type int -