I am newbie angularjs developer. I have,
var app = angular.module('myapp', []);
app.controller('ProductCtrl', ['$scope', '$sce', function ($scope, $sce) {
$scope.products = myapp.products;
$scope.pager = $sce.trustAsHtml(myapp.pager);
$scope.getProducts = function($event) {
$event.preventDefault();
var $link = $($event.target);
var url = $event.target.href;
$.getJSON(url, function(response) {
$scope.$apply(function() {
$scope.products = response.products;
$scope.pager = $sce.trustAsHtml(response.pager);
});
history.pushState(response, "Index", url);
});
};
}]);
$(window).bind("popstate", function (e) {
console.log(e.originalEvent.state);// I need scope here
});
You can see that clicking will call getProducts
methods which will update $scope.products and $scope.pager. I am also doing history.pushState
. Now, what I want, whenever user click the back button, I need to update $scope.products
and $scope.pager
again. Is that possible with AngularJS?