From d53eab819728e56ec3ee9a0906b79e277c30c07e Mon Sep 17 00:00:00 2001 From: Andy Joslin Date: Thu, 27 Mar 2014 10:47:16 -0600 Subject: [PATCH] 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 ``` To this: ```html ``` --- js/ext/angular/src/directive/ionicContent.js | 2 +- .../angular/src/directive/ionicViewState.js | 21 ++++++++++++------- .../angular/test/directive/ionicView.unit.js | 12 ++++++++++- 3 files changed, 25 insertions(+), 10 deletions(-) diff --git a/js/ext/angular/src/directive/ionicContent.js b/js/ext/angular/src/directive/ionicContent.js index e18683cc7cb..f65e7a2d470 100644 --- a/js/ext/angular/src/directive/ionicContent.js +++ b/js/ext/angular/src/directive/ionicContent.js @@ -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 diff --git a/js/ext/angular/src/directive/ionicViewState.js b/js/ext/angular/src/directive/ionicViewState.js index 4eb907bd890..d6aa8c96f8c 100644 --- a/js/ext/angular/src/directive/ionicViewState.js +++ b/js/ext/angular/src/directive/ionicViewState.js @@ -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 diff --git a/js/ext/angular/test/directive/ionicView.unit.js b/js/ext/angular/test/directive/ionicView.unit.js index 86a32c7976c..deb34fd8d5c 100644 --- a/js/ext/angular/test/directive/ionicView.unit.js +++ b/js/ext/angular/test/directive/ionicView.unit.js @@ -33,7 +33,17 @@ describe('ionView directive', function() { expect(el.html()).toBe('some 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'); });