Filtering your data – using query parameters

So far we have been dealing with routing parameters on the format of tasks/:id. Links formed like that tell us that the context is tasks and to get to one particular task, we need to specify which one, by specifying its number. It's about narrowing down to the specific data we are interested in. Query parameters have a different job, they aim to either sort your data or narrow down the size of your data set:

// for sorting
/tasks/114?sortOrder=ascending

// for narrowing down the data set
/tasks/114?page=3&pageSize=10

Query parameters are recognized as everything happening after the ? character and are separated by an and (&) sign. To get to those values, we can work with the ActivatedRoute, just like we did with routing parameters but we look at a different collection on the ActivatedRouter instance:

constructor(private route: ActivatedRoute) {}

getData(){
this.route.queryParamMap
.switchMap( data => {
let pageSize = data.get('pageSize');
let page = data.get('page');
return this._service.getTaskLimited(pageSize,page);
})
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset