Skip to content

Commit 919d4f8

Browse files
committed
fix(ionView): make it set navbar if title changes back to old value
Fixes #1121
1 parent 4814a63 commit 919d4f8

File tree

4 files changed

+19
-9
lines changed

4 files changed

+19
-9
lines changed

Diff for: js/angular/controller/navBarController.js

+3
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,9 @@ function($scope, $element, $attrs, $ionicViewService, $animate, $compile, $ionic
5252
};
5353

5454
this.setTitle = function(title) {
55+
if ($scope.title === title) {
56+
return;
57+
}
5558
$scope.oldTitle = $scope.title;
5659
$scope.title = title || '';
5760
};

Diff for: js/angular/directive/view.js

+1-7
Original file line numberDiff line numberDiff line change
@@ -52,14 +52,8 @@ IonicModule
5252

5353
// watch for changes in the title, don't set initial value as changeTitle does that
5454
$attr.$observe('title', function(val, oldVal) {
55-
if (val !== initialTitle) {
56-
navBarCtrl.setTitle(val);
57-
} else {
58-
//Safety to make sure the navbar's title is correct
59-
navBarCtrl.setTitle(initialTitle);
60-
}
55+
navBarCtrl.setTitle(val);
6156
});
62-
6357
}
6458

6559
var hideBackAttr = angular.isDefined($attr.hideBackButton) ?

Diff for: test/unit/angular/directive/navBar.unit.js

+13
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,19 @@ describe('ionNavBar', function() {
107107
expect($scope.oldTitle).toBe('bar');
108108
});
109109

110+
it('setTitle should not change if title is same as old', function() {
111+
var ctrl = setup();
112+
ctrl.setTitle('okay');
113+
expect($scope.title).toBe('okay');
114+
expect($scope.oldTitle).toBeFalsy();
115+
ctrl.setTitle('okay');
116+
expect($scope.title).toBe('okay');
117+
expect($scope.oldTitle).toBeFalsy();
118+
ctrl.setTitle('okay-2');
119+
expect($scope.title).toBe('okay-2');
120+
expect($scope.oldTitle).toBe('okay');
121+
});
122+
110123
it('should getTitle', function() {
111124
var ctrl = setup();
112125
expect(ctrl.getTitle()).toBeFalsy();

Diff for: test/unit/angular/directive/view.unit.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -76,10 +76,10 @@ describe('ionView directive', function() {
7676
expect(el.controller('ionNavBar').showBar).toHaveBeenCalledWith(true);
7777
});
7878

79-
it('should setTitle on change, but not with initial value', function() {
79+
it('should setTitle on change', function() {
8080
var el = setup('title="{{something}}-1"');
8181
//Should not setTitle with initial value
82-
expect(el.controller('ionNavBar').setTitle).not.toHaveBeenCalled();
82+
expect(el.controller('ionNavBar').setTitle).toHaveBeenCalledWith('-1');
8383
el.scope().$apply('something = 2');
8484
expect(el.controller('ionNavBar').setTitle).toHaveBeenCalledWith('2-1');
8585
});

0 commit comments

Comments
 (0)