typescript url search params code example
Example 1: get url params in typescript
import {Router, ActivatedRoute, Params} from '@angular/router';
import {OnInit, Component} from '@angular/core';
@Component({...})
export class MyComponent implements OnInit {
constructor(private activatedRoute: ActivatedRoute) {}
ngOnInit() {
this.activatedRoute.queryParams.subscribe(params => {
const userId = params['userId'];
console.log(userId);
});
}
}
Example 2: typescript read url search params
const product = urlParams.get('product')
console.log(product);
const color = urlParams.get('color')
console.log(color);
const newUser = urlParams.get('newuser')
console.log(newUser);