Skip to content

Instantly share code, notes, and snippets.

@DeepSky8
Created September 7, 2016 18:17
Show Gist options
  • Save DeepSky8/b1543465796e67b650919d965115a053 to your computer and use it in GitHub Desktop.
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
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