mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2026-03-13 10:22:08 +08:00
fix(viewController): use $watch instead of $observe
This commit is contained in:
14
js/angular/controller/viewController.js
vendored
14
js/angular/controller/viewController.js
vendored
@@ -40,7 +40,7 @@ function($scope, $element, $attrs, $compile, $ionicHistory, $ionicViewSwitcher)
|
||||
// add listeners for when this view changes
|
||||
$scope.$on('$ionicView.beforeEnter', self.beforeEnter);
|
||||
$scope.$on('$ionicView.afterEnter', afterEnter);
|
||||
$scope.$on('$ionicView.beforeLeave', deregisterObservers);
|
||||
$scope.$on('$ionicView.beforeLeave', deregisterFns);
|
||||
};
|
||||
|
||||
self.beforeEnter = function(ev, transData) {
|
||||
@@ -72,7 +72,7 @@ function($scope, $element, $attrs, $compile, $ionicHistory, $ionicViewSwitcher)
|
||||
});
|
||||
|
||||
// make sure any existing observers are cleaned up
|
||||
deregisterObservers();
|
||||
deregisterFns();
|
||||
}
|
||||
};
|
||||
|
||||
@@ -89,14 +89,14 @@ function($scope, $element, $attrs, $compile, $ionicHistory, $ionicViewSwitcher)
|
||||
}
|
||||
|
||||
if (isDefined($attrs.hideBackButton)) {
|
||||
deregisters.push($attrs.$observe('hideBackButton', function() {
|
||||
navViewCtrl.showBackButton(!attrTrue('hideBackButton'));
|
||||
deregisters.push($scope.$watch($attrs.hideBackButton, function(val) {
|
||||
navViewCtrl.showBackButton(!val);
|
||||
}));
|
||||
}
|
||||
|
||||
if (isDefined($attrs.hideNavBar)) {
|
||||
deregisters.push($attrs.$observe('hideNavBar', function() {
|
||||
navViewCtrl.showBar(!attrTrue('hideNavBar'));
|
||||
deregisters.push($scope.$watch($attrs.hideNavBar, function(val) {
|
||||
navViewCtrl.showBar(!val);
|
||||
}));
|
||||
}
|
||||
|
||||
@@ -104,7 +104,7 @@ function($scope, $element, $attrs, $compile, $ionicHistory, $ionicViewSwitcher)
|
||||
}
|
||||
|
||||
|
||||
function deregisterObservers() {
|
||||
function deregisterFns() {
|
||||
// remove all existing $attrs.$observe's
|
||||
for (var x = 0; x < deregisters.length; x++) {
|
||||
deregisters[x]();
|
||||
|
||||
Reference in New Issue
Block a user