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
  • Hi, have a look at [this] (stackoverflow.com/questions/45997369/…). Also can you provide how you pass the params? Commented Nov 11, 2019 at 15:07
  • The second log should be this.route.snapshot.paramMap instead of .params Commented Nov 11, 2019 at 15:41

2 Answers 2

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 ... :)

Sign up to request clarification or add additional context in comments.

1 Comment

@SoufianChaoui you are using the wrong key, check out this... this.route.queryParams.subscribe( params => { console.log(params[param_key]); } )
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);
    });
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.