search

Home  >  Q&A  >  body text

angular.js - $localStorage is injected into the run method of angularjs, why is it undiffed when printed on the console

When I logged in, I stored the username in localStorage and wanted to verify the permissions based on localStorage information in stateChangeStart. However, I injected $localStorage in the run method and could not get the value of $localStorage. The page would report an error, $localStorage As undefined, what's going on?

世界只因有你世界只因有你2867 days ago660

reply all(1)I'll reply

  • 漂亮男人

    漂亮男人2017-05-15 17:13:05

    localStorage is a property under window, not angularJS. So there is no need to inject it, just use it directly

    if( window.localStorage ){
        //do sth...
    }
    

    For details, please refer to:

    https://developer.mozilla.org...

    reply
    0
  • Cancelreply