mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2026-03-13 10:22:08 +08:00
fix(ionView): make it set navbar if title changes back to old value
Fixes #1121
This commit is contained in:
3
js/angular/controller/navBarController.js
vendored
3
js/angular/controller/navBarController.js
vendored
@@ -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 || '';
|
||||
};
|
||||
|
||||
8
js/angular/directive/view.js
vendored
8
js/angular/directive/view.js
vendored
@@ -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) ?
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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');
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user