Created
September 7, 2016 18:17
-
-
Save DeepSky8/b1543465796e67b650919d965115a053 to your computer and use it in GitHub Desktop.
The run method defined on my AngularJS module. I'm learning how to accommodate multiple functions in one run method in javascript
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
site.run(function (editableOptions) { | |
editableOptions.theme = 'bs3'; // bootstrap3 theme. Can be also 'bs2', 'default' | |
}, | |
['$rootScope', '$location', '$cookieStore', '$http', | |
function ($rootScope, $location, $cookieStore, $http) { | |
// keep user logged in after page refresh | |
$rootScope.globals = $cookieStore.get('globals') || {}; | |
if ($rootScope.globals.currentUser) { | |
$http.defaults.headers.common['Authorization'] = 'Basic ' + $rootScope.globals.currentUser.authdata; // jshint ignore:line | |
} | |
$rootScope.$on('$locationChangeStart', function (event, next, current) { | |
// redirect to login page if not logged in | |
if ($location.path() !== '/login' && !$rootScope.globals.currentUser) { | |
$location.path('/login'); | |
} | |
}); | |
}]); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment