Skip to content

Instantly share code, notes, and snippets.

@shashibest
Forked from jakemmarsh/directives.js
Created February 9, 2017 05:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shashibest/ff8c2881bf80498e3debb2ed34159e4f to your computer and use it in GitHub Desktop.
Save shashibest/ff8c2881bf80498e3debb2ed34159e4f to your computer and use it in GitHub Desktop.
AngularJS directive to create a functional "back" button
app.directive('backButton', function(){
return {
restrict: 'A',
link: function(scope, element, attrs) {
element.bind('click', goBack);
function goBack() {
history.back();
scope.$apply();
}
}
}
});
<a href back-button>back</a>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment