Skip to content

Instantly share code, notes, and snippets.

@dillonforrest
Created February 21, 2014 19:13
Show Gist options
  • Save dillonforrest/9141238 to your computer and use it in GitHub Desktop.
Save dillonforrest/9141238 to your computer and use it in GitHub Desktop.
angular.module('campfire', [
'templates-app',
'templates-common',
'ngBoilerplate.home',
'ngBoilerplate.about',
'ui.state',
'ui.route',
'UserSrvc'
])
.config(['$stateProvider', '$urlRouterProvider',
function myAppConfig($stateProvider, $urlRouterProvider) {
$stateProvider
.state('apples', {
url : '/apples',
template : '<p>apples</p>'
})
.state('bananas', {
url : '/bananas',
template : '<p>bananas</p>'
})
.state('login', {
url : '/login',
template : '<p>login</p>'
})
;
$urlRouterProvider.otherwise('login');
}])
.run(['$rootScope', '$location', 'UserService',
function run($rootScope, $location, User) {
$rootScope.$on('$locationChangeStart',
function checkLogin(evt, newRoute, oldRoute) {
if (!User.loggedIn) {
evt.preventDefault();
$location.path('/login');
$location.replace();
}
});
}])
.controller('AppCtrl', function AppCtrl($scope, $location) {
$scope.$on('$stateChangeSuccess',
function(event, toState, toParams, fromState, fromParams){
if ( angular.isDefined(toState.data && toState.data.pageTitle) ) {
$scope.pageTitle = toState.data.pageTitle + ' | TripleLift' ;
} else {
$scope.pageTitle = 'TripleLift';
}
});
})
;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment