0

I'm trying the get the url parameters in angular i've tried

 ngOnInit() {   

   this.route.paramMap.subscribe(params => {
     console.log("test1",params)
}) 
//and
console.log("test2", this.route.snapshot.params)

 }
ngAfterViewInit(){


}

The response it get : enter image description here

2 Answers2

1
constructor() {
    const query = new URLSearchParams(location.search);
    console.log(query.get('param_key')); // www.google.com?size=123 --- param_key is size here

}

Try out this and let me know if missing anything ... Happy coding ... :)

Zee
  • 483
  • 3
  • 10
  • @SoufianChaoui you are using the wrong key, check out this... this.route.queryParams.subscribe( params => { console.log(params[param_key]); } ) – Zee Nov 11 '19 at 15:27
0

Are you using ActivatedRouter class or Router class? When router is of class Router then this should work.

import { Router } from '@angular/router';

...
constructor(private router: Router) {
     this.router.params.subscribe(params => {
     console.log('my parameters: ', params);
    });
}
Kheder
  • 203
  • 3
  • 9