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>
```
This commit is contained in:
Andy Joslin
2014-03-27 10:47:16 -06:00
parent bf5c46cbe1
commit d53eab8197
3 changed files with 25 additions and 10 deletions

View File

@@ -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

View File

@@ -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

View File

@@ -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');
});