Last active
March 22, 2016 11:38
-
-
Save KarafiziArtur/653b380a2f5d0ebc8509 to your computer and use it in GitHub Desktop.
Basics config for Angular ui-router
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
.config(routes); | |
routes.$inject = ['$urlRouterProvider', '$stateProvider']; | |
function routes($urlRouterProvider, $stateProvider) { | |
$urlRouterProvider.otherwise('/login'); | |
$stateProvider | |
.state('login', { | |
url: '/login', | |
templateUrl: 'views/login.tpl.html', | |
controller: 'LoginController as lc' | |
}); |
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
.run(['$rootScope', '$state', firstRun]); | |
function firstRun($rootScope, $state) { | |
$rootScope.$on('$stateChangeError', | |
function(event, toState, toParams, fromState, fromParams, error) { | |
if (error === 'AUTH_REQUIRED') { | |
event.preventDefault(); | |
$state.go('login'); | |
} | |
}); | |
} |
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
<ul class="user-menu"> | |
<li ui-sref-active="active" ng-hide="currentUser"> <!-- ui-sref-active sets class if this page are opened. Hide if user are not registered--> | |
<a ui-sref="login">Login</a> <!-- ui-sref opens target page --> | |
</li> | |
<li ui-sref-active="active" ng-hide="currentUser"> | |
<a ui-sref="register">Register</a> | |
</li> | |
</ul> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment