1

I have the following url ,

product/example/:example/example1/:example1?query1=:query1&query2=:query2

I want to get the values that is specified in the path and query parameters, I have tried this but it retrieves only the path variables not the query params

this.sub = this.route.params.subscribe(params => {
  this.example= params['example'];
  this.example1 = params['example1'];
  this.query1=params['query1'];
  this.query2=params['query2'];
});

Is there a way that I can get all 4 values ?

2 Answers 2

5

I think the ActivatedRoutehas a property called queryParams, try subscribing to that and not to params. Example

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

Comments

3
constructor(private activatedRoute: ActivatedRoute) { }
    
  ngOnInit(): void {
    this.activatedRoute.params.subscribe(s => {
      console.log(s["id"])
    });

// Other way 
    console.log(this.activatedRoute.snapshot.paramMap.get('id'));

  }

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.