mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2026-03-13 10:22:08 +08:00
watchCollection on right- and leftButtons to align headerBar title
This commit is contained in:
4
js/ext/angular/src/directive/ionicBar.js
vendored
4
js/ext/angular/src/directive/ionicBar.js
vendored
@@ -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();
|
||||
});
|
||||
|
||||
@@ -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();
|
||||
});
|
||||
|
||||
|
||||
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user