1

I can't see the problem at all, here's my code.

var app = angular.module('application', ['ui.router', 'ngResource','user.controllers','user.services']);

app.config(function ($stateProvider, $urlRouterProvider) {

  $stateProvider.state('home', {
    url: '',
    templateUrl: 'views/home.html'

  }).state('account', {
    url: '/account',
    templateUrl: 'views/user/account.html',
    controller: 'UserCtrl'

  }).state('login', {
    url: '/login',
    templateUrl: 'views/user/login.html',
    controller: 'UserCtrl'

  }).state('logout', {
    url: '/logout',
    templateUrl: 'views/user/logout.html',
    controller: 'UserCtrl'

  }).state('register', {
    url: '/register',
    templateUrl: 'views/user/register.html',
    controller: 'UserCtrl'
  });
});


app.run(function ($rootScope, $state) {
  $rootScope.$on("$stateChangeStart", function (event, toState, toParams, fromState, fromParams) {
    console.log('toState.name: ' + toState.name);
    console.log('fromState.name: ' + fromState.name)
  });
});

It seems pretty straightforward to do, but it just doesn't work. I'm sure it's a little thing I don't know about Angular, so any help would be appreciated.

Thank you!

1 Answer 1

2

In the code you posted, it looks like you're missing a closing }) at the end of your $stateProvider.state declaration.


UPDATE:

DEMO EXAMPLE (Plunker)

Sign up to request clarification or add additional context in comments.

3 Comments

Thank you for taking time to answer, but it was a copy-paste error, I edited my entry.
Do you know why when I add event.preventDefault(); and $state.go('login'); inside $rootScope.$on, it doesn't go to the login state?
Put the $state.go('login'); before the event.preventDefault(); and it should work

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.