I have a function that I use to handle pagination in my Angular app. It was working as expected - I subscribe to the url params and then use the router to navigate according to those params while taking in the page number as a passed in value. One param is a boolean indicating whether the filter is currently active, and the second param is the value(s) itself for the filter.
This is the working version:
public paginate(page) {
this.route.params.subscribe(
(params: any) => {
this.pn_location_e = params['pn_location_e'];
this.pn_location_v = params['pn_location_v'];
}
);
this.router.navigate(
['/clients', {
page: page,
pn_location_e: this.pn_location_e,
pn_location_v: this.pn_location_v,
}]);
let fn = resRecordsData => {
this.records = resRecordsData;
let data = resRecordsData.data;
};
this.dataService.filterByInput(
page - 1, this.pagesize, this.location, fn);
}
Everything above was working as expected.
However, recently a colleague changed the filter syntax from using an "_" to using a ".". So it went from this:
this.pn_location_e = params['pn_location_e'];
to this:
this.pn_location.e = params['pn_location.e'];
The problem is, in my Angular component I can't initialize the variable with that syntax. When I try and initialize like this:
pn_location.e
... I get a syntax error. I also tried doing this pn_location['.e'], but that also won't work (also causes a syntax error).
Is there a way around this? Or do we just need to go back to using the underscore syntax for our filters params?