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: 
Query and Path Params (Angular 8)
---------------------------------

For url like <https://myapp.com/user/666/read?age=23> use

```
import { combineLatest } from 'rxjs';
// ...

combineLatest( [this.route.paramMap, this.route.queryParamMap] )
  .subscribe( ([pathParams, queryParams]) => {
    let userId = pathParams.get('userId');    // =666
    let age    = queryParams.get('age');      // =23
    // ...
  })

```

UPDATE
------

In case when you use `this.router.navigate([someUrl]);` and your query parameters are embedded in `someUrl` string then angular encodes a URL and you get something like this <https://myapp.com/user/666/read%3Fage%323> - and above solution will give wrong result (queryParams will be empty, and path params can be glued to last path param if it is on the path end). In this case change the way of navigation [to this](https://github.com/angular/angular/issues/28917)

```
this.router.navigateByUrl(someUrl);

```
Stumbled across this question when I was looking for a similar solution but I didn't need anything like full application level routing or more imported modules. 

The following code works great for my use and requires no additional modules or imports. 

```
  GetParam(name){
    const results = new RegExp('[\\?&]' + name + '=([^&#]*)').exec(window.location.href);
    if(!results){
      return 0;
    }
    return results[1] || 0;
  }

  PrintParams() {
    console.log('param1 = ' + this.GetParam('param1'));
    console.log('param2 = ' + this.GetParam('param2'));
  }

```

`http://localhost:4200/?param1=hello&param2=123` outputs:

```
param1 = hello
param2 = 123

```