作为新的角我想知道如何调用一个应通过URL解析和配对的Web服务,就像如果URL被直接调用以获得列出的请求与给定PARAMS地图AngularJS通过URL的restAPI请求
我的意思让说我有
/api/products -- calling all products(this is the access point)
/api/products/?page=2&orderby=asc -- calls products with pagination and orderby and here is what's bothering me because the api is getting called via ajax and there is no URL mapping of the target
我的代码
HTML标记
<div ng-controller="MainCtrl">
<div class="row">
<div class="col-lg-7 col-md-7 col-sm-7">
<pagination total-items="totalItems" num-pages="totalPages" ng-model="currentPage" ng-change="selectPage(currentPage)" max-size="5" class="pagination-sm" boundary-links="true"></pagination>
</div>
<div ng-repeat="product in products"></div>
</div>
</div>
位指示
//called when navigate to another page in the pagination
$scope.selectPage = function(page) {
$scope.filterCriteria.pageNumber = page;
$scope.fetchResult();
};
//The function that is responsible of fetching the result from the server and setting the grid to the new result
$scope.fetchResult = function() {
return api.items.search($scope.filterCriteria).then(function(data) {
$scope.products = data;
$scope.totalPages = data.total;
$scope.productsCount = data.TotalItems;
}, function() {
$scope.products = [];
$scope.totalPages = 0;
$scope.productsCount = 0;
});
};
服务
.factory('api', function(Restangular) {
//api call to
return {
products: function() {
return Restangular.all('products').getList();
},
product: function(id) {
Restangular.one("products", id).get().then(function(c) {
return c;
});
},
update: function(id) {
Restangular.one("products", id).put().then(function(c) {
return c;
});
},
items: {
search: function(query) {
return Restangular.all('products').getList(query);
}
},
};
});
如何创建的PARAMS URL和功能这使RESTAPI来电或什么在这种情况下的解决方法
我提出代码工作,我想要的东西:用户给出了浏览器http://somedomain.com/products/?page=2&orderby=asc比restangular定义了API的调用像http://somedomain.com/products/?page=2&orderby=asc – fefe
那应该在角度路由器级别处理。您使用角度或角度ui路由器提供的默认路由器? – V31
我正在使用'ngRoute' – fefe