I'm new to angular and I'm trying to use angular ui router. When I navigate to /
I get this abstract state as my $state.current
: Object {name: "", url: "^", views: null, abstract: true}
. Is there anyway around this so that my current state is files
? Here is my code:
(function() {
'use strict';
angular.module('carton', [
'ui.router',
'carton.controllers',
'carton.services',
'carton.directives'
]).
config([
'$stateProvider',
'$urlRouterProvider',
function(
$stateProvider,
$urlRouterProvider
) {
$urlRouterProvider.otherwise('/');
$stateProvider.
state('files', {
url: '/',
templateUrl: 'partials/files.html',
//controller: 'FilesCtrl'
access: {
isFree: false
}
}).
state('login', {
url: '/login',
templateUrl: 'partials/login.html',
controller: 'loginCtrl',
access: {
isFree: true
}
}).
state('register', {
url: '/register',
templateUrl: 'partials/register.html',
//controller: 'RegisterCtrl'
access: {
isFree: true
}
});
}
])
.run(['$rootScope', '$state', 'UserService',
function($root, $state, userSrv) {
$root.$on(
'$locationChangeSuccess',
function(event) {
console.log($state.current);
if (!$state.current.access.isFree && !userSrv.isLogged) {
$state.go('login');
}
}
)
}
]);
})();