Skip to content

Commit

Permalink
fix(ionView): make it set navbar if title changes back to old value
Browse files Browse the repository at this point in the history
Fixes #1121
  • Loading branch information
ajoslin committed May 9, 2014
1 parent 4814a63 commit 919d4f8
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 9 deletions.
3 changes: 3 additions & 0 deletions js/angular/controller/navBarController.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ function($scope, $element, $attrs, $ionicViewService, $animate, $compile, $ionic
};

this.setTitle = function(title) {
if ($scope.title === title) {
return;
}
$scope.oldTitle = $scope.title;
$scope.title = title || '';
};
Expand Down
8 changes: 1 addition & 7 deletions js/angular/directive/view.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,8 @@ IonicModule

// 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);
} else {
//Safety to make sure the navbar's title is correct
navBarCtrl.setTitle(initialTitle);
}
navBarCtrl.setTitle(val);
});

}

var hideBackAttr = angular.isDefined($attr.hideBackButton) ?
Expand Down
13 changes: 13 additions & 0 deletions test/unit/angular/directive/navBar.unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,19 @@ describe('ionNavBar', function() {
expect($scope.oldTitle).toBe('bar');
});

it('setTitle should not change if title is same as old', function() {
var ctrl = setup();
ctrl.setTitle('okay');
expect($scope.title).toBe('okay');
expect($scope.oldTitle).toBeFalsy();
ctrl.setTitle('okay');
expect($scope.title).toBe('okay');
expect($scope.oldTitle).toBeFalsy();
ctrl.setTitle('okay-2');
expect($scope.title).toBe('okay-2');
expect($scope.oldTitle).toBe('okay');
});

it('should getTitle', function() {
var ctrl = setup();
expect(ctrl.getTitle()).toBeFalsy();
Expand Down
4 changes: 2 additions & 2 deletions test/unit/angular/directive/view.unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,10 @@ describe('ionView directive', function() {
expect(el.controller('ionNavBar').showBar).toHaveBeenCalledWith(true);
});

it('should setTitle on change, but not with initial value', function() {
it('should setTitle on change', function() {
var el = setup('title="{{something}}-1"');
//Should not setTitle with initial value
expect(el.controller('ionNavBar').setTitle).not.toHaveBeenCalled();
expect(el.controller('ionNavBar').setTitle).toHaveBeenCalledWith('-1');
el.scope().$apply('something = 2');
expect(el.controller('ionNavBar').setTitle).toHaveBeenCalledWith('2-1');
});
Expand Down

0 comments on commit 919d4f8

Please sign in to comment.