Need help implementing a filtering mechanism in my new Angular2 app. Looking to filter a list of entries in an array based on around 20 properties. I've set up filters in one component and a list component as a child that is routed to.
Initially, passing just one filter using queryParams through the router was okay:
this.router.navigate(['/findlist'], {queryParams: {'g': myParam}});
Then receiving the filter on the other side:
this.subscription = this.route.queryParams.subscribe(
(queryParam: any) => this.myFilter = queryParam['g']
);
However, struggling to scale this for multiple potential Params. Trying to figure out how to pass an array of active filters through queryParams without getting errors.
Thinking of maintaining an array of all filters and their states on the send side, updating values in the array whenever a filter button is clicked, then passing the entire array through queryParams each time.
On the receive side, would need to process the Param as an array and extract each entry as variables to process in the filter. Want to avoid repetition and cycle through an array instead.
Open to suggestions on improving this workflow or alternative methods to pass filter data. Considering creating a separate filter service and using @Input instead.
Any ideas appreciated! (Self-taught amateur so might be missing something obvious!)
Thanks, Tony