fix(ionView): make it set navbar if title changes back to old value

Fixes #1121
This commit is contained in:
Andrew Joslin
2014-05-09 08:43:15 -06:00
parent 4814a63bda
commit 919d4f8dca
4 changed files with 19 additions and 9 deletions

View File

@@ -52,6 +52,9 @@ function($scope, $element, $attrs, $ionicViewService, $animate, $compile, $ionic
};
this.setTitle = function(title) {
if ($scope.title === title) {
return;
}
$scope.oldTitle = $scope.title;
$scope.title = title || '';
};

View File

@@ -52,14 +52,8 @@ IonicModule
// watch for changes in the title, don't set initial value as changeTitle does that
$attr.$observe('title', function(val, oldVal) {
if (val !== initialTitle) {
navBarCtrl.setTitle(val);
} else {
//Safety to make sure the navbar's title is correct
navBarCtrl.setTitle(initialTitle);
}
navBarCtrl.setTitle(val);
});
}
var hideBackAttr = angular.isDefined($attr.hideBackButton) ?

View File

@@ -107,6 +107,19 @@ describe('ionNavBar', function() {
expect($scope.oldTitle).toBe('bar');
});
it('setTitle should not change if title is same as old', function() {
var ctrl = setup();
ctrl.setTitle('okay');
expect($scope.title).toBe('okay');
expect($scope.oldTitle).toBeFalsy();
ctrl.setTitle('okay');
expect($scope.title).toBe('okay');
expect($scope.oldTitle).toBeFalsy();
ctrl.setTitle('okay-2');
expect($scope.title).toBe('okay-2');
expect($scope.oldTitle).toBe('okay');
});
it('should getTitle', function() {
var ctrl = setup();
expect(ctrl.getTitle()).toBeFalsy();

View File

@@ -76,10 +76,10 @@ describe('ionView directive', function() {
expect(el.controller('ionNavBar').showBar).toHaveBeenCalledWith(true);
});
it('should setTitle on change, but not with initial value', function() {
it('should setTitle on change', function() {
var el = setup('title="{{something}}-1"');
//Should not setTitle with initial value
expect(el.controller('ionNavBar').setTitle).not.toHaveBeenCalled();
expect(el.controller('ionNavBar').setTitle).toHaveBeenCalledWith('-1');
el.scope().$apply('something = 2');
expect(el.controller('ionNavBar').setTitle).toHaveBeenCalledWith('2-1');
});