Skip to content

Commit

Permalink
fix(backButton): dynamic icon/text updates
Browse files Browse the repository at this point in the history
Allow back button icon/text to be updated after app initialization.
Closes #3281
  • Loading branch information
adamdbradley committed Apr 6, 2015
1 parent 0936f78 commit a0c3c55
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 3 deletions.
25 changes: 23 additions & 2 deletions js/angular/controller/headerBarController.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,31 @@ function($scope, $element, $attrs, $q, $ionicConfig, $ionicHistory) {


self.updateBackButton = function() {
var ele;
if ((isBackShown && isNavBackShown && isBackEnabled) !== isBackElementShown) {
isBackElementShown = isBackShown && isNavBackShown && isBackEnabled;
var backBtnEle = getEle(BACK_BUTTON);
backBtnEle && backBtnEle.classList[ isBackElementShown ? 'remove' : 'add' ](HIDE);
ele = getEle(BACK_BUTTON);
ele && ele.classList[ isBackElementShown ? 'remove' : 'add' ](HIDE);
}

if (isBackEnabled) {
ele = ele || getEle(BACK_BUTTON);
if (ele) {
if (self.backButtonIcon !== $ionicConfig.backButton.icon()) {
ele = getEle(BACK_BUTTON + ' .icon');
if (ele) {
self.backButtonIcon = $ionicConfig.backButton.icon();
ele.className = 'icon ' + self.backButtonIcon;
}
}

if (self.backButtonText !== $ionicConfig.backButton.text()) {
ele = getEle(BACK_BUTTON + ' .back-text');
if (ele) {
ele.textContent = self.backButtonText = $ionicConfig.backButton.text();
}
}
}
}
};

Expand Down
3 changes: 2 additions & 1 deletion js/angular/controller/navBarController.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ function($scope, $element, $attrs, $compile, $timeout, $ionicNavBarDelegate, $io
var lastViewItemEle = {};
var leftButtonsEle, rightButtonsEle;

//navEle[BACK_BUTTON] = self.createBackButtonElement(headerBarEle);
navEle[BACK_BUTTON] = createNavElement(BACK_BUTTON);
navEle[BACK_BUTTON] && headerBarEle.append(navEle[BACK_BUTTON]);

Expand All @@ -79,6 +78,8 @@ function($scope, $element, $attrs, $compile, $timeout, $ionicNavBarDelegate, $io
$element.append($compile(containerEle)($scope.$new()));

var headerBarCtrl = headerBarEle.data('$ionHeaderBarController');
headerBarCtrl.backButtonIcon = $ionicConfig.backButton.icon();
headerBarCtrl.backButtonText = $ionicConfig.backButton.text();

var headerBarInstance = {
isActive: isActive,
Expand Down

3 comments on commit a0c3c55

@snjak
Copy link

@snjak snjak commented on a0c3c55 Aug 31, 2015

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So this should work now by using

$ionicConfig.backButton.text('') in controller? It's not working for me, I uploaded ionic to 1.1.0. @adamdbradley

@hhlevnjak
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems that it doesn't work still.

@ShaAbdullah
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is still not @adamdbradley.. plz check this

Please sign in to comment.