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


#1

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!


Function is not executed each time the controllador opens
#2

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


#3

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.


#4

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:


#5

@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


#6

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


#7

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:


#8

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


#9

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