angularjs - ui-router reinitializing angular controllers on state change -


is there easy way using ui-router force controllers initialized once? singleton. of right now, every time change state, controller linked state reinitialized. don't want happen. seems should simple, not find solution anywhere online.

a common way handle things one-time or global operations have application level controller on element wraps ui-views:

<html ng-app="app">     <head>...</head>     <body ng-controller="applicationcontroller">         <div ui-view></div>     </body> </html> 

applicationcontroller can reponsible one-time operations. gets initialised once (when app starts) , persist between route , state changes.

the controllers associated states should concerned constructing own views, not performing one-time operations. if state controllers need access shared data, data should stored in service suggested abos. state controllers should request shared data service, , service should 1 deciding if should return cached data, or make fresh service call.


Popular posts from this blog