Skip to content

Commit d53eab8

Browse files
committed
fix(ionView): do not set navbar title if no title attr set
Fixes #915 BREAKING CHANGE: Before, if you did not have a `title` attribute set on your ion-view, it would transition into that view and erase the navbar's current title. Now, if your ion-view does not have a `title` attribute set, the new view will be transitioned in, but there will be no title change. If you wish to have a blank title on your new view, you must now explicitly set your `ion-view`'s title attribute to an empty string. To migrate your code, change from this: ```html <ion-view></ion-view> ``` To this: ```html <ion-view title=""></ion-view> ```
1 parent bf5c46c commit d53eab8

File tree

3 files changed

+25
-10
lines changed

3 files changed

+25
-10
lines changed

Diff for: js/ext/angular/src/directive/ionicContent.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ angular.module('ionic.ui.content', ['ionic.ui.scroll'])
4848
* with {@link ionic.service:$ionicScrollDelegate}.
4949
* @param {boolean=} padding Whether to add padding to the content.
5050
* of the content. Defaults to true on iOS, false on Android.
51-
* @param {boolean=} scroll Whether to allow scrolling of content. Defaults to true. Note: scroll="false" removes the .scroll child element on element compilation, not on scope change
51+
* @param {boolean=} scroll Whether to allow scrolling of content. Defaults to true.
5252
* @param {boolean=} overflow-scroll Whether to use overflow-scrolling instead of
5353
* Ionic scroll.
5454
* @param {boolean=} has-bouncing Whether to allow scrolling to bounce past the edges

Diff for: js/ext/angular/src/directive/ionicViewState.js

+13-8
Original file line numberDiff line numberDiff line change
@@ -48,15 +48,20 @@ angular.module('ionic.ui.viewState', ['ionic.service.view', 'ionic.service.gestu
4848
if (!navBarCtrl) {
4949
return;
5050
}
51-
var initialTitle = $attr.title;
52-
navBarCtrl.changeTitle(initialTitle, $scope.$navDirection);
5351

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-
});
52+
if (angular.isDefined($attr.title)) {
53+
54+
var initialTitle = $attr.title;
55+
navBarCtrl.changeTitle(initialTitle, $scope.$navDirection);
56+
57+
// watch for changes in the title, don't set initial value as changeTitle does that
58+
$attr.$observe('title', function(val, oldVal) {
59+
if (val !== initialTitle) {
60+
navBarCtrl.setTitle(val);
61+
}
62+
});
63+
64+
}
6065

6166
$scope.$watch($attr.hideBackButton, function(value) {
6267
// Should we hide a back button when this tab is shown

Diff for: js/ext/angular/test/directive/ionicView.unit.js

+11-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,17 @@ describe('ionView directive', function() {
3333
expect(el.html()).toBe('<b>some</b> html');
3434
});
3535

36-
it('should changeTitle with a navDirection', function() {
36+
it('should not changeTitle with undefined title attr', function() {
37+
var el = setup();
38+
expect(el.controller('ionNavBar').changeTitle).not.toHaveBeenCalled();
39+
});
40+
41+
it('should changeTitle with blank if title attr is blank', function() {
42+
var el = setup('title=""', {$navDirection: 'someDirection'});
43+
expect(el.controller('ionNavBar').changeTitle).toHaveBeenCalledWith('', 'someDirection');
44+
});
45+
46+
it('should changeTitle with a navDirection if title set', function() {
3747
var el = setup('title="Hi, {{1}}!"', {$navDirection: 'foo'});
3848
expect(el.controller('ionNavBar').changeTitle).toHaveBeenCalledWith('Hi, 1!', 'foo');
3949
});

0 commit comments

Comments
 (0)