8
我正在使用angular来创建电子商务,并且我将无限滚动设置为产品列表页面。一切正常,但我想使用URL来设置页面,所以用户可以通过URL访问特定页面。如何在URL中设置像“pageNumber”这样的变量?像“www.page.com/page/2/"(I想要得到的2号,并将其传递到存储控制器)通过带角js的URL传递变量
这里是我的代码现在
(function() {
var app = angular.module('concurseirosUnidos', ['store-directives', 'ngRoute']);
app.config(function($routeProvider, $locationProvider){
$locationProvider.html5Mode(true);
$routeProvider
.when('/', {templateUrl: 'partials/products-list.html'})
.when("/page/$pageNumber"), {
// probably I'd need to put something here?
})
.otherwise({redirectTo:'/'});;
}
});
app.controller('StoreController', ['$http', '$scope', function($http, $scope){
var store = this;
store.products = [];
$http.get('/app/products/products.json').success(function(data){
store.products = data;
});
if(typeof page === 'undefined'){
var page = 1;
}else{
//if it's defined through the url, page = pageNumberFromURL
}
$scope.myLimit = 3 * page;
$scope.nextPage = function() {
page++; // I want this function to actually update the url and get the variable from there
$scope.myLimit = 3 * page;
};
}]);
})();
噢,谢谢... – 2014-09-01 16:27:50
如果有解决了您的问题,您可以将此标记为接受的答案。 – ryeballar 2014-09-01 16:30:34
当然= D,我只是在检查是否没有其他问题...再次感谢你 – 2014-09-01 16:51:14