2016-09-15 111 views
0

據我所知,在app.config只有提供者和常量是注入配置塊,但我找不到任何有效的解決方案,我的情況。在App.config中訪問localstorage

我有一個app.config這樣的:

angular 
    .module('app.core')  
    .config(initDebug) 
    .config(initRouter) 
    .config(initStorage) 

所有我想要的是注入common服務: angular .module('app.core') .factory('common', ($location, $q, $rootScope, messageService, globalData) => { return new Common($location, $q, $rootScope, messageService, globalData); });

我在這app-config一個UI的路由器,我想做出一個麪包屑與加入對象如:

state('class-add?itemId', { 
      url: '/classAdd?itemId', 
      templateUrl: '/app/classes/class-add.partial.html', 
      controller: 'ClassesController', 
      controllerAs: 'vm',     
      ncyBreadcrumb: {     
       ---> here goes the common.SelectedClass (from localstorage) 
      }     
     }) 

任何幫助嗎?

回答

0

angular-local-storage是角JS +本地存儲需求的最佳解決方案

myApp.config(function (localStorageServiceProvider) { 
    localStorageServiceProvider 
    .setPrefix('myApp') 
    .setStorageType('sessionStorage') 
    .setNotify(true, true) 
});