I get the following error from angular -ui-router:
TypeError: Cannot read property '@' of null ... TypeError: Cannot read property '@main' of null ...
I did some research on what could be causing this error, and came to the conclusion that the problem is that I am redirecting when the condition is false through the state $ state.go (state) during the onEnter of another state.
Here are some discussions regarding the same issue on github:
I tried some of the suggestions, but they do not work. They don't seem to give a solution, they just point to a problem, and according to this github discussion should be resolved, but I can. It seems to work.
I am using AngularJS v1.2.24 and ui-router v0.2.11.
Using the following code (simplified):
.state('main', { abstract: true, url: '/main', templateUrl: '/main/_layout.html' }) .state('main.home', { url: '/home', templateUrl: '/main/home/home.html', controller: 'HomeCtrl', onEnter: function ($state) { if (condition === true){ $state.go('main.catch') } } }) .state('main.catch', { url: '/catch', templateUrl: '/main/catch/catch.html', controller: 'CatchCtrl' })
Is there any way to make this work? Or should I consider a completely different approach to achieving the same result?
PS: A possible fix is ββto do the following in the controller,
$scope.$on('$stateChangeSuccess', function(){
But I do not want to do this in HomeCtrl.