watchCollection on right- and leftButtons to align headerBar title

This commit is contained in:
Tim Lancina
2014-02-28 11:26:38 -06:00
parent cfbb9d6002
commit fa05f4b2ab
2 changed files with 38 additions and 2 deletions

View File

@@ -48,12 +48,12 @@ angular.module('ionic.ui.header', ['ngAnimate', 'ngSanitize'])
$scope.headerBarView = hb;
$scope.$watch('leftButtons', function(val) {
$scope.$watchCollection('leftButtons', function(val) {
// Resize the title since the buttons have changed
hb.align();
});
$scope.$watch('rightButtons', function(val) {
$scope.$watchCollection('rightButtons', function(val) {
// Resize the title since the buttons have changed
hb.align();
});

View File

@@ -54,4 +54,40 @@ describe('Ionic Header Bar', function() {
});
});
it('Should re-align the title when leftButtons change', function() {
rootScope.leftButtons = [];
el = compile('<ion-header-bar left-buttons="leftButtons" align-title="right"></ion-header-bar>')(rootScope);
var headerView = el.isolateScope().headerBarView;
//trigger initial align()
rootScope.$apply();
spyOn(headerView, 'align');
var button = { content: '<i class="icon ion-gear-a"></i>' };
rootScope.leftButtons.push(button);
rootScope.$apply();
expect(headerView.align).toHaveBeenCalled();
});
it('Should re-align the title when rightButtons change', function() {
rootScope.rightButtons = [];
el = compile('<ion-header-bar right-buttons="rightButtons" align-title="right"></ion-header-bar>')(rootScope);
var headerView = el.isolateScope().headerBarView;
//trigger initial align()
rootScope.$apply();
spyOn(headerView, 'align');
var button = { content: '<i class="icon ion-gear-a"></i>' };
rootScope.rightButtons.push(button);
rootScope.$apply();
expect(headerView.align).toHaveBeenCalled();
});
});