1import { ActivatedRoute } from '@angular/router';
2
3export class ExampleComponent implements OnInit {
4
5 constructor(private router: ActivatedRoute) { }
6
7 ngOnInit() {
8 this.router.queryParams.subscribe(res=>{
9 console.log(res) //will give query params as an object
10 })
11 }
12
13}
1request(query) {
2 let params = new HttpParams().set("keyword", query);
3 return this.http.get(`Your_URL`, {params});
4}
1constructor(private router: Router) { }
2
3public myMethodChangingQueryParams() {
4 const queryParams: Params = { myParam: 'myNewValue' };
5
6 this.router.navigate(
7 [],
8 {
9 relativeTo: activatedRoute,
10 queryParams: queryParams,
11 queryParamsHandling: 'merge', // remove to replace all query params by provided
12 });
13}
1export class HeroComponent implements OnInit {
2 constructor(private _activatedRoute: ActivatedRoute, private _router:Router) {
3 _router.routerState.queryParams.subscribe(
4 params => console.log('queryParams', params['st']));