2016-09-15 115 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) 
});