Skip to content

Instantly share code, notes, and snippets.

@KarafiziArtur
Last active March 22, 2016 11:38
Show Gist options
  • Save KarafiziArtur/653b380a2f5d0ebc8509 to your computer and use it in GitHub Desktop.
Save KarafiziArtur/653b380a2f5d0ebc8509 to your computer and use it in GitHub Desktop.
Basics config for Angular ui-router
.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'
});
.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');
}
});
}
<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