1
$http.post(url, data).then(function (response) {

    // TypeError: Cannot read property '$destroy' of null
    $state.go('some.page'); 

    // No Error
    $timeout(function () {
        $state.go('some.page'); 
    }, 500);
});

500ms delay prevent from error.

Why instant page change gives "Cannot read property '$destroy' of null" error?

CroMagnon
  • 1,218
  • 7
  • 20
  • 32

1 Answers1

0

My initial thought on this was wondering where the best place to use $state.go is. I have always used it in the controller and didn't even know you could do it in the service... But at the end of the day, it shouldn't matter. So I did some googling on it and found this issue on github! It seems to have the same problem that was solved with a timeout but just by moving the $state.go into the controller fixes it as well.

https://github.com/angular-ui/ui-router/issues/403

Hope it this helps!

Edit: Here is another stackoverflow question about something similar

AngularJS behaving strangely when there's a nested relationship of promises in services

joshbang
  • 181
  • 11