diff --git a/dist/js/ionic-angular.js b/dist/js/ionic-angular.js index 399207d597..cc3152fa55 100644 --- a/dist/js/ionic-angular.js +++ b/dist/js/ionic-angular.js @@ -2626,14 +2626,20 @@ angular.module('ionic.ui.viewState', ['ionic.service.view', 'ionic.service.gestu $rootScope.$broadcast('viewState.showNavBar', !$scope.hideNavBar); // watch for changes in the left buttons - $scope.$watch('leftButtons', function(value) { + var deregLeftButtons = $scope.$watch('leftButtons', function(value) { $scope.$emit('viewState.leftButtonsChanged', $scope.leftButtons); }); - $scope.$watch('rightButtons', function(val) { + var deregRightButtons = $scope.$watch('rightButtons', function(val) { $scope.$emit('viewState.rightButtonsChanged', $scope.rightButtons); }); + $scope.$on('$destroy', function(){ + // deregister on destroy + deregLeftButtons(); + deregRightButtons(); + }); + }; } }; diff --git a/js/ext/angular/src/directive/ionicViewState.js b/js/ext/angular/src/directive/ionicViewState.js index 6cfaa25ee6..f4cc996c79 100644 --- a/js/ext/angular/src/directive/ionicViewState.js +++ b/js/ext/angular/src/directive/ionicViewState.js @@ -185,14 +185,20 @@ angular.module('ionic.ui.viewState', ['ionic.service.view', 'ionic.service.gestu $rootScope.$broadcast('viewState.showNavBar', !$scope.hideNavBar); // watch for changes in the left buttons - $scope.$watch('leftButtons', function(value) { + var deregLeftButtons = $scope.$watch('leftButtons', function(value) { $scope.$emit('viewState.leftButtonsChanged', $scope.leftButtons); }); - $scope.$watch('rightButtons', function(val) { + var deregRightButtons = $scope.$watch('rightButtons', function(val) { $scope.$emit('viewState.rightButtonsChanged', $scope.rightButtons); }); + $scope.$on('$destroy', function(){ + // deregister on destroy + deregLeftButtons(); + deregRightButtons(); + }); + }; } };