How to implement history.back() in angular.js
by manoj
HTML
<link rel="stylesheet" href="http://twitter.github.com/bootstrap/assets/css/bootstrap.css">
<script src="http://code.jquery.com/jquery-1.7.2.min.js"></script>
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.0.3/angular.js"></script>
<div ng-controller="Ctrl">
<site-header back="back" forward="forward"></site-header>
</div>
JavaScript
var app = angular.module('myApp', []);
app.directive('siteHeader', function () {
return {
restrict: 'E',
template: '<button class="btn">{{back}}</button><button class="btn">{{forward}}</button>',
scope: {
back: '@back',
forward: '@forward',
icons: '@icons'
},
link: function(scope, element, attrs) {
$(element[0]).on('click', function() {
history.back();
scope.$apply();
});
$(element[1]).on('click', function() {
history.forward();
scope.$apply();
});
}
};
});
function Ctrl($scope) {
}