Share Data Between Controllers In Angularjs
I use the following factory to fetch data from API and store it to local variable called apiData. app.factory('MyFactory', function($resource, $q) { var apiData = []; var
Solution 1:
You should use $resource to get $promise eg: resource.query().$promise
instead of $q.defer()
for cleaner code. Otherwise you are good to go. You could use $cacheFactory
, but you can also use local var.
Isn't your shared variable in a current state with current code?
I recommend you take a look at ui-router and its nested and abstract views, where resolved values are available to child controllers.
Post a Comment for "Share Data Between Controllers In Angularjs"