Question: I'm using angular 5.0.3, I would like to start my application with a bunch of query parameters like `/app?param1=hallo&param2=123`. Every tip given in [How to get query params from url in Angular 2?](https://stackoverflow.com/questions/35688084/how-get-query-params-from-url-in-angular2/37962626) does not work for me.

Any ideas how to get query parameters work?

```
private getQueryParameter(key: string): string {
  const parameters = new URLSearchParams(window.location.search);
  return parameters.get(key);
}

```

This private function helps me to get my parameters, but I don't think it is the right way in new Angular environment.

[update:]
My main app looks like

```
@Component({...})
export class AppComponent implements OnInit {

  constructor(private route: ActivatedRoute) {}

  ngOnInit(): void {
    // would like to get query parameters here...
    // this.route...
  }
}

```

Answer: 
This is the cleanest solution for me

```here
import { Component, OnInit } from '@angular/core';
import { ActivatedRoute } from '@angular/router';

export class MyComponent {
  constructor(
    private route: ActivatedRoute
  ) {}

  ngOnInit() {
    const firstParam: string = this.route.snapshot.queryParamMap.get('firstParamKey');
    const secondParam: string = this.route.snapshot.queryParamMap.get('secondParamKey');
  }
}

```
You can also Use [HttpParams](https://angular.io/api/common/http/HttpParams), such as: 

```
  getParamValueQueryString( paramName ) {
    const url = window.location.href;
    let paramValue;
    if (url.includes('?')) {
      const httpParams = new HttpParams({ fromString: url.split('?')[1] });
      paramValue = httpParams.get(paramName);
    }
    return paramValue;
  }

```