Skip to content

Commit

Permalink
fix(ionView): do not set navbar title if no title attr set
Browse files Browse the repository at this point in the history
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>
```
  • Loading branch information
ajoslin committed Mar 27, 2014
1 parent bf5c46c commit d53eab8
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 10 deletions.
2 changes: 1 addition & 1 deletion js/ext/angular/src/directive/ionicContent.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ angular.module('ionic.ui.content', ['ionic.ui.scroll'])
* with {@link ionic.service:$ionicScrollDelegate}.
* @param {boolean=} padding Whether to add padding to the content.
* of the content. Defaults to true on iOS, false on Android.
* @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
* @param {boolean=} scroll Whether to allow scrolling of content. Defaults to true.
* @param {boolean=} overflow-scroll Whether to use overflow-scrolling instead of
* Ionic scroll.
* @param {boolean=} has-bouncing Whether to allow scrolling to bounce past the edges
Expand Down
21 changes: 13 additions & 8 deletions js/ext/angular/src/directive/ionicViewState.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,20 @@ angular.module('ionic.ui.viewState', ['ionic.service.view', 'ionic.service.gestu
if (!navBarCtrl) {
return;
}
var initialTitle = $attr.title;
navBarCtrl.changeTitle(initialTitle, $scope.$navDirection);

// 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);
}
});
if (angular.isDefined($attr.title)) {

var initialTitle = $attr.title;
navBarCtrl.changeTitle(initialTitle, $scope.$navDirection);

// 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);
}
});

}

$scope.$watch($attr.hideBackButton, function(value) {
// Should we hide a back button when this tab is shown
Expand Down
12 changes: 11 additions & 1 deletion js/ext/angular/test/directive/ionicView.unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,17 @@ describe('ionView directive', function() {
expect(el.html()).toBe('<b>some</b> html');
});

it('should changeTitle with a navDirection', function() {
it('should not changeTitle with undefined title attr', function() {
var el = setup();
expect(el.controller('ionNavBar').changeTitle).not.toHaveBeenCalled();
});

it('should changeTitle with blank if title attr is blank', function() {
var el = setup('title=""', {$navDirection: 'someDirection'});
expect(el.controller('ionNavBar').changeTitle).toHaveBeenCalledWith('', 'someDirection');
});

it('should changeTitle with a navDirection if title set', function() {
var el = setup('title="Hi, {{1}}!"', {$navDirection: 'foo'});
expect(el.controller('ionNavBar').changeTitle).toHaveBeenCalledWith('Hi, 1!', 'foo');
});
Expand Down

0 comments on commit d53eab8

Please sign in to comment.