Skip to content

$scope.$watch not disengaged in time, $state gone #2643

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
phazei opened this issue Mar 23, 2016 · 2 comments
Closed

$scope.$watch not disengaged in time, $state gone #2643

phazei opened this issue Mar 23, 2016 · 2 comments

Comments

@phazei
Copy link

phazei commented Mar 23, 2016

This issue happens on 0.2.18, but started from 0.2.16, last worked on 0.2.15 and discovered it.

I have a controller with a $watch on a method that uses a $stateParams, when changing state away from the page, the $watch is called one last time that it hadn't ever been prior. The new view is already loaded, and the $stateParams from the page with the controller aren't there.

$scope.$watch(function() { return myMethod($scope.$stateParams) }, function(response) {

});

I'm injecting $stateParams into the $rootScope in .run(). If I inject $stateParams directly into the controller its fine.

But why isn't the $watcher being cleared until after the view has changed? What changed in 0.2.16 that leaves the $watcher that much longer? Shouldn't it be cleared before the next view has been loaded?

@phazei
Copy link
Author

phazei commented Mar 23, 2016

Actually, it doesn't just effect $watch, but other items that are bound in the view and watched. I have a page with a

//template:
<button ng-disabled="myFunc()">
//controller:
$scope.myFunc = function() {
    return $scope.form.item == 'value';
}

Which on changing state away from the form page gives is called after the page has changed with an error about $scope.form being undefined.

Now I have to check everything that might be called while the page exists, still exists when leaving the state...

@phazei phazei changed the title $scope.$watch not disengaged in time, stateParams gone $scope.$watch not disengaged in time, state gone Mar 24, 2016
@phazei phazei changed the title $scope.$watch not disengaged in time, state gone $scope.$watch not disengaged in time, $state gone Mar 24, 2016
@christopherthielen
Copy link
Contributor

dupe #2614
Recommend using 0.2.15 until we release 0.2.19

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants