简体   繁体   中英

AngularJS $rootScope in factory - reload data

I have a factory calling a $resource. Upon refreshing the application entirely, this works as planned. But it not call the resource again throughout navigating the application. Ideally i would like the $resource called every time i call the factory from the controller.

app.factory("factoryList", function ($cookieStore, $resource, $http, $location, $window) {

   var List = $resource('/api/list');
   $http.defaults.headers.common['auth-token'] = $cookieStore.get("api_key") + ':' + $cookieStore.get("api_token");
   return List.get();

});

This is my controller:

consoleApp.controller('mainController', function ($rootScope, $window, $scope, $resource, $http, $route, $location, $cookieStore, factoryList) {

$rootScope.list = factoryList;

});

这是我创建的小提琴jsfiddle.net/HB7LU/5833/,我可以看到导航之间更新的内容

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM