Hi guys, I am using angular ui-router and i have a case in which i have 2 views, 'A' and 'B' now if user updates something in 'A' view controller and navigates to 'B' view and after that when he came back to view 'A' he should have his changes as same. If you know about ui-router it reinitialize the controller each time the route is updated, i tried using the $state.transitionTo with this options -
But this doesn't fulfil my requirement, what i am looking for is to Update the view and url without reloading controller in some cases.
Lead Fullstack Developer. Experimenting with bleeding-edge tech. Irregularly DJ. Hobby drone pilot. Amateur photographer.
Use an event bus to notify the second controller of changes that happened in the first controller and vice versa. Or even better, load the data onto the eventbus and both controllers can subscribe to that specific message and both will be updated.
Why not save the needed data in a service? seems like your data should not be in a controller.
I think there was a confusion in my explanation, what i am looking for is -
ROUTE : /xyz
CONTROLLER :
...
$scope.selected_data = [{
name: "hello",
value : "world"
}];
...
ROUTE : /abc
CONTROLLER :
...
$scope.some_var = "";
...
Now Imagine the case as, default route is /xyz and user is there he done some selection and now he jumped to /abc, if he comes back to /xyz he will loose his selection he did in /xyz as when he navigates between routes it reloads the controller, What i am looking for is a way form which i can disable reloading the controller while navigating with ui-rotuter.
Hope this clears what i meant! :)
Sandeep Panda
co-founder, Hashnode
How about storing the unsaved changes in a cache? May be
localStorageorsessionStorage? When the user is in/xyzand selects a few things ($scope.selected_data), you can store the data in cache. When the user goes to a different view and comes back to the old one/xyz, you can read from the cache and re-initialize the$scopemodels.