Skip to content

Instantly share code, notes, and snippets.

@MathRivest
Last active August 29, 2015 14:24
Show Gist options
  • Save MathRivest/6ebff721e89b40804ee8 to your computer and use it in GitHub Desktop.
Save MathRivest/6ebff721e89b40804ee8 to your computer and use it in GitHub Desktop.
Back button directive for AngularJS. Using the $state
'use strict';
angular.module('fitcart.common.directives', []).directive('backButton', require('./back-button'));
module.exports = /*@ngInject*/ function($window) {
return {
restrict: 'E',
replace: true,
template: '<button class="btn-back" ng-show="!hideBack" ng-cloak>Back</button>',
controller: function($scope, $state){
$scope.$on('$stateChangeSuccess', function (event, toState) {
$scope.hideBack = $state.current.hideBack ? $state.current.hideBack : false;
});
},
link: function(scope, element, attrs) {
element.bind('click', function () {
console.log('going back...');
$window.history.back();
});
}
};
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment