Skip to content

Commit 4d1b13b

Browse files
committed
refact(ionView): do not call setTitle with initialTitle
1 parent fb83ded commit 4d1b13b

File tree

2 files changed

+16
-14
lines changed

2 files changed

+16
-14
lines changed

js/ext/angular/src/directive/ionicViewState.js

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,15 @@ angular.module('ionic.ui.viewState', ['ionic.service.view', 'ionic.service.gestu
4848
if (!navBarCtrl) {
4949
return;
5050
}
51-
navBarCtrl.changeTitle($attr.title, $scope.$navDirection);
51+
var initialTitle = $attr.title;
52+
navBarCtrl.changeTitle(initialTitle, $scope.$navDirection);
53+
54+
// watch for changes in the title, don't set initial value as changeTitle does that
55+
$attr.$observe('title', function(val, oldVal) {
56+
if (val !== initialTitle) {
57+
navBarCtrl.setTitle(val);
58+
}
59+
});
5260

5361
$scope.$watch($attr.hideBackButton, function(value) {
5462
// Should we hide a back button when this tab is shown
@@ -60,12 +68,6 @@ angular.module('ionic.ui.viewState', ['ionic.service.view', 'ionic.service.gestu
6068
navBarCtrl.showBar(!value);
6169
});
6270

63-
// watch for changes in the title
64-
$attr.$observe('title', function(val, oldVal) {
65-
if (val) {
66-
navBarCtrl.setTitle(val);
67-
}
68-
});
6971
};
7072
}
7173
};

js/ext/angular/test/directive/ionicView.unit.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
'use strict';
2-
3-
describe('ionView directive', function() {
1+
ddescribe('ionView directive', function() {
42
beforeEach(module('ionic.ui.viewState'));
53

64
function setup(attrs, scopeProps, content) {
@@ -58,9 +56,11 @@ describe('ionView directive', function() {
5856
expect(el.controller('ionNavBar').showBar).toHaveBeenCalledWith(true);
5957
});
6058

61-
it('should setTitle on change', function() {
62-
var el = setup('title="{{something}}1"');
63-
el.scope().$apply('something = "bar"');
64-
expect(el.controller('ionNavBar').setTitle).toHaveBeenCalledWith('bar1');
59+
it('should setTitle on change, but not with initial value', function() {
60+
var el = setup('title="{{something}}-1"');
61+
//Should not setTitle with initial value
62+
expect(el.controller('ionNavBar').setTitle).not.toHaveBeenCalled();
63+
el.scope().$apply('something = 2');
64+
expect(el.controller('ionNavBar').setTitle).toHaveBeenCalledWith('2-1');
6565
});
6666
});

0 commit comments

Comments
 (0)