[solved] $state.go redirect to page, but does not hit controller

Hello everyone! I’m have the following scenario:

I have a login page with button. This button must redirect to another page (hence, to another controller, right?)

function RedirectToHome(){
  $state.go('app.playlists');
}

So I call like this:

$scope.loginFacebook = function() {
  RedirectToHome();
}

Playlist controller declaration:

.state('app.playlists', {
  url: "/playlists",
  views: {
    'menuContent' :{
      templateUrl: "templates/playlists.html",
      controller: 'PlaylistsCtrl'
    }
  }
})

Login’s controller declaration:

.state('login', {
  url: "/login",
  templateUrl: "templates/login.html",
  controller: 'LoginCtrl'
})

This project is based on side-menu template.

Everything seems fine, the page change, but the controller is not called. So, the data its not loaded.

Do I have to call it explicitly in a different way?

Thank you!

my first guess is view caching… Not alot of code to use so I am guessing

Sorry, I edited the topic with more details about the issue.

My app is based on the side menu template, and the login page is separated from this architecture, maybe the login’s controller declaration is wrong.

1 Like

I figured out: cache: false did the trick.
Sample code:

.state('app.playlists', {
  cache: false,
  url: "/playlists",
  views: {
    'menuContent' :{
      templateUrl: "templates/playlists.html",
      controller: 'PlaylistsCtrl'
    }
  }
})

Hope it help someone. :smile:

1 Like

@raphaelpinheiro i’m also facing the same issue, whenever i try to redirect to a different controller using the $state.go and my page doesnot load properly, if i refresh the page in the browser it loads perfectly but not on redirecting.
Can you please help me with this

@anshulklr, It’s due state caching. Just cache: false, on your controller definition (app.js), like I’ve said above.

the cache: false thing is not helping me. I’m still finding the problem with this. The header doesn’t show up and the page loads up properly. When i refresh the page everything becomes correct with the header showing up :frowning:

+1 on the same problem.
@max - this is the same problem I tagged you few minutes back. Many are facing this very same problem.

Be sure your javascript (app.js/controllers.js) is not cached. Try ctrl+f5 to force download them.