Skip to content

Instantly share code, notes, and snippets.

@valerysntx
Forked from mlynch/ionicNavState.js
Created March 7, 2014 13:00
Show Gist options
  • Save valerysntx/9411017 to your computer and use it in GitHub Desktop.
Save valerysntx/9411017 to your computer and use it in GitHub Desktop.
directive('tab', ['NavStateDelegate', '$scope', function(NavStateDelegate, $scope) {
return {
//
link: function($scope, $element, $attr) {
// Indicate to this delegate we want to control a nav bar
NavStateDelegate.enable(scope);
}
}
}])
// Service
factory('NavStateDelegate', function() {
return {
register: function($scope) {
// Should we hide a back button when this tab is shown
$scope.hideBackButton = $scope.$eval($scope.hideBackButton);
$scope.hideNavBar = $scope.$eval($scope.hideNavBar);
navCtrl.navBar.isVisible = !$scope.hideNavBar;
if($scope.hideBackButton === true) {
$scope.$emit('navRouter.hideBackButton');
} else {
$scope.$emit('navRouter.showBackButton');
}
// watch for changes in the left buttons
$scope.$watch('leftButtons', function(value) {
$scope.$emit('navRouter.leftButtonsChanged', $scope.leftButtons);
});
$scope.$watch('rightButtons', function(val) {
$scope.$emit('navRouter.rightButtonsChanged', $scope.rightButtons);
});
// watch for changes in the title
$scope.$watch('title', function(value) {
$scope.$emit('navRouter.titleChanged', {
title: value,
animate: $scope.animate
});
});
}
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment