在App.config中访问localstorage

时间:2016-09-15 09:46:12

标签: angularjs typescript

据我所知,在app.config中,只有提供程序和常量可以在配置块中注入,但我无法为我的案例找到任何有效的解决方案。

我有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-router,我想用加密对象做一个面包屑,如:

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)
            }                
        })

任何帮助?

1 个答案:

答案 0 :(得分:-1)

angular-local-storage是Angular JS +本地存储要求的绝佳解决方案

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