mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2026-03-13 10:22:08 +08:00
refact(ionView): do not call setTitle with initialTitle
This commit is contained in:
16
js/ext/angular/src/directive/ionicViewState.js
vendored
16
js/ext/angular/src/directive/ionicViewState.js
vendored
@@ -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);
|
||||
}
|
||||
});
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
@@ -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');
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user