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();
}
```
This commit is contained in:
Andy Joslin
2014-04-08 09:35:09 -06:00
parent 24a415c32d
commit 933a555e08

View File

@@ -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) {