Skip to content

Instantly share code, notes, and snippets.

@pstricks-fans
Last active July 1, 2022 21:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pstricks-fans/a4b6497461d210eb18c9ea52d37eb6e3 to your computer and use it in GitHub Desktop.
Save pstricks-fans/a4b6497461d210eb18c9ea52d37eb6e3 to your computer and use it in GitHub Desktop.

Folks, I am a newbie and learning Angular in a random order.

I have a question: Is it possible to retrieve a collection of query string values and assign them to a property of type Filter in a service component class?

interface Filter{
    title?: string;
    genreId?: number;
    inCinemas?: boolean;
    upcomingReleases?: boolean;
}

rather than doing the following tedious error prone retrieval and assignment?

  constructor(private route: ActivatedRoute) { }
ngOnInit(): void {
  this.route.paramMap.subscribe({
    next: params => this.title = params.get('title'),
    error: e => console.log(e)
  });
  this.route.paramMap.subscribe({
    next: params => this.genreId = params.get('genreId'),
    error: e => console.log(e)
  });
  this.route.paramMap.subscribe({
    next: params => this.inCinemas = params.get('inCinemas'),
    error: e => console.log(e)
  });
  this.route.paramMap.subscribe({
    next: params => this.UpcomingReleases = params.get('upcomingReleases'),
    error: e => console.log(e)
  });
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment