Get values from URL query string in Angular

0
177
Angular

Example of how to get values from query string from URL in Angular 7.

Example of get values from URL

You need to use following class to get values from query string.

Suppose We want to get value of “id” parameter from URL.

Open component.ts file

import { Router, ActivatedRoute, ParamMap } from '@angular/router';
constructor(private router:Router,  private route: ActivatedRoute){

}
ngOnInit() {
let id = this.route.snapshot.paramMap.get('id');
console.log(id);
}

By above code you can get the value of id parameter.

LEAVE A REPLY

Please enter your comment!
Please enter your name here