获取历史popstate事件AngularJs $范围是什么?范围、事件、历史、popstate

由网友(林间有新绿)分享简介:我是新手angularjs开发商。我有,I am newbie angularjs developer. I have,var app = angular.module('myapp', []);app.controller('ProductCtrl', ['$scope', '$sce', function (...

我是新手angularjs开发商。我有,

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
});

您可以看到,点击后会调用的getProducts方法whihc将更新$ scope.products和$ scope.pager。我也做history.pushState。现在,我想要什么,只要用户点击后退按钮,我需要更新$ scope.products又一次$ scope.pager。这是可能与AngularJs?

You can see that clicking will call getProducts methods whihc 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?

推荐答案

您在混合 Jquery的 Angularjs 。现在,这个可以和经常已经做了许多有用的库要求 Jquery的

You are mixing Jquery and Angularjs. Now this can and often has been done as many useful libraries require Jquery.

但你重新创建的很多角度的使用jQuery在这里的功能

首先你应该看看角的 $ routeProvider $ locationProvider.html5Mode(真); 这将真正轻松地在您的应用程序的导航和历史。这里是href="http://scotch.io/tutorials/javascript/single-page-apps-with-angularjs-routing-and-templating" rel="nofollow">好的博客帖子到

阅读全文

相关推荐

最新文章