refact(ionView): do not call setTitle with initialTitle

This commit is contained in:
Andy Joslin
2014-03-25 12:16:52 -06:00
parent fb83ded8b1
commit 4d1b13b5ad
2 changed files with 16 additions and 14 deletions

View File

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

View File

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