From 933a555e084234462ad04b7255bd1a0e0c6b2aef Mon Sep 17 00:00:00 2001 From: Andy Joslin Date: Tue, 8 Apr 2014 09:35:09 -0600 Subject: [PATCH] feat($ionicNavBarDelegate): showBackButton returns whether bar is shown Closes #1076 If the user for example switches tabs, $ionicNavBarDelegate.getPreviousTitle() will return the title from the navbar within the previous tab. In this case, the back button will not be shown. To not use the previous title in a case like this, you can now do: ```js var shouldShowTitle = $ionicNavBarDelegate.showBackButton(); if (shouldShowTitle) { $scope.previousTitle = $ionicNavBarDelegate.getPreviousTitle(); } ``` --- js/ext/angular/src/directive/ionicNavBar.js | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/js/ext/angular/src/directive/ionicNavBar.js b/js/ext/angular/src/directive/ionicNavBar.js index 80ebe1f51a..de02f03fcc 100644 --- a/js/ext/angular/src/directive/ionicNavBar.js +++ b/js/ext/angular/src/directive/ionicNavBar.js @@ -47,9 +47,10 @@ angular.module('ionic.ui.navBar', ['ionic.service.view', 'ngSanitize']) * @ngdoc method * @name $ionicNavBarDelegate#showBackButton * @description - * Set whether the {@link ionic.directive:ionNavBackButton} should be shown + * Set/get whether the {@link ionic.directive:ionNavBackButton} is shown * (if it exists). - * @param {boolean} show Whether to show the back button. + * @param {boolean=} show Whether to show the back button. + * @returns {boolean} Whether the back button is shown. */ 'showBackButton', /** @@ -140,7 +141,10 @@ function($scope, $element, $attrs, $ionicViewService, $animate, $compile, $ionic }; this.showBackButton = function(show) { - $scope.backButtonShown = !!show; + if (arguments.length) { + $scope.backButtonShown = !!show; + } + return !!($scope.hasBackButton && $scope.backButtonShown); }; this.showBar = function(show) {