angular get query params from route code example

Example 1: angular http request query params

request(query) {
  let params = new HttpParams().set("keyword", query);
  return this.http.get(`Your_URL`, {params});
}

Example 2: angular set query params

constructor(private router: Router) { }

public myMethodChangingQueryParams() {
  const queryParams: Params = { myParam: 'myNewValue' };

  this.router.navigate(
    [], 
    {
      relativeTo: activatedRoute,
      queryParams: queryParams, 
      queryParamsHandling: 'merge', // remove to replace all query params by provided
    });
}

Example 3: in angular how to get router url without query params

this.router.url.split('?')[0]

Example 4: get route query params angular

export class HeroComponent implements OnInit {
  constructor(private _activatedRoute: ActivatedRoute, private _router:Router) {
    _router.routerState.queryParams.subscribe(
      params => console.log('queryParams', params['st']));