import { URLSearchParams } from '@angular/http'; const params = new URLSearchParams(); params.set('name', 'John'); params.set('age', '30'); console.log(params.toString()); // name=John&age=30
import { ActivatedRoute } from '@angular/router'; import { URLSearchParams } from '@angular/http'; constructor(private route: ActivatedRoute) {} ngOnInit() { const params = new URLSearchParams(this.route.snapshot.queryParams); const name = params.get('name'); console.log(name); // John }In this example, we use the `ActivatedRoute` service to get the current query parameters from the URL. We then create a new `URLSearchParams` object, pass in the query parameters to the constructor, and use the `get` method to retrieve the value of the `name` parameter. The `@angular/http` library is an official library from the Angular team that provides tools for making HTTP requests and working with HTTP responses.