From 4d1b13b5ad3907af01129fd441e7334366e94906 Mon Sep 17 00:00:00 2001 From: Andy Joslin Date: Tue, 25 Mar 2014 12:16:52 -0600 Subject: [PATCH] refact(ionView): do not call setTitle with initialTitle --- js/ext/angular/src/directive/ionicViewState.js | 16 +++++++++------- js/ext/angular/test/directive/ionicView.unit.js | 14 +++++++------- 2 files changed, 16 insertions(+), 14 deletions(-) diff --git a/js/ext/angular/src/directive/ionicViewState.js b/js/ext/angular/src/directive/ionicViewState.js index fa4dd87548..4eb907bd89 100644 --- a/js/ext/angular/src/directive/ionicViewState.js +++ b/js/ext/angular/src/directive/ionicViewState.js @@ -48,7 +48,15 @@ angular.module('ionic.ui.viewState', ['ionic.service.view', 'ionic.service.gestu if (!navBarCtrl) { return; } - navBarCtrl.changeTitle($attr.title, $scope.$navDirection); + 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 @@ -60,12 +68,6 @@ angular.module('ionic.ui.viewState', ['ionic.service.view', 'ionic.service.gestu navBarCtrl.showBar(!value); }); - // watch for changes in the title - $attr.$observe('title', function(val, oldVal) { - if (val) { - navBarCtrl.setTitle(val); - } - }); }; } }; diff --git a/js/ext/angular/test/directive/ionicView.unit.js b/js/ext/angular/test/directive/ionicView.unit.js index b024adbf75..9d5cf4081c 100644 --- a/js/ext/angular/test/directive/ionicView.unit.js +++ b/js/ext/angular/test/directive/ionicView.unit.js @@ -1,6 +1,4 @@ -'use strict'; - -describe('ionView directive', function() { +ddescribe('ionView directive', function() { beforeEach(module('ionic.ui.viewState')); function setup(attrs, scopeProps, content) { @@ -58,9 +56,11 @@ describe('ionView directive', function() { expect(el.controller('ionNavBar').showBar).toHaveBeenCalledWith(true); }); - it('should setTitle on change', function() { - var el = setup('title="{{something}}1"'); - el.scope().$apply('something = "bar"'); - expect(el.controller('ionNavBar').setTitle).toHaveBeenCalledWith('bar1'); + it('should setTitle on change, but not with initial value', function() { + var el = setup('title="{{something}}-1"'); + //Should not setTitle with initial value + expect(el.controller('ionNavBar').setTitle).not.toHaveBeenCalled(); + el.scope().$apply('something = 2'); + expect(el.controller('ionNavBar').setTitle).toHaveBeenCalledWith('2-1'); }); });