I have a Spring
controller which takes one argument - Pageable
:
@RequestMapping(value = "/all", method = RequestMethod.GET)
public Page<Item> getAll(Pageable pageable) {
return itemService.findAll(pageable);
}
Via Postman
I can call this api
by providing query params
as: http://localhost:8080/api/item/all?page=0&size=2
and I got a json
response with two elements.
How can I call this kind of api in Angular 4
? Is there any other way to send query params
in Angular 4
than this?:
getItems(page, size){
return this.http.get(this.url + '/all?page=' + page + '&size=' + size);
}
I would like to use something like:
ngOnInit() {
let search = new URLSearchParams();
search.set('page', '0');
search.set('size', "2");
console.log('------------', search);
this.itemService.getItems({search:search})
.subscribe(res => {
console.log('teitems', res.json());
this.items = res.json().content;
});
}
But generally it doesn't work at all and the search object looks suspicious because of the fact:
What is more in network
tab of my browser request looks like:
So as you see the request URL
differ from that which I posted above from Postman
.