2016-09-15 2 views
0

Ich verstehe, dass in app.config nur Anbieter und Konstanten in Konfigurationsblöcke injizierbar sind, aber ich kann keine gültige Lösung für meinen Fall finden.Zugriff auf localstorage in App.config

Ich habe ein app.config wie:

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

Alles, was ich will, ist die common Dienst zu injizieren: angular .module('app.core') .factory('common', ($location, $q, $rootScope, messageService, globalData) => { return new Common($location, $q, $rootScope, messageService, globalData); });

Ich habe einen ui-Router in diesem app-config und ich möchte ein Brotkrümel machen mit accesed Objekt wie:

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

Jede Hilfe?

Antwort

0

angular-local-storage ist eine großartige Lösung für Angular JS + Local Storage Anforderungen

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