get url params in typescript

Solutions on MaxInterview for get url params in typescript by the best coders in the world

showing results for - "get url params in typescript"
Giacomo
29 Sep 2020
1import {Router, ActivatedRoute, Params} from '@angular/router';
2import {OnInit, Component} from '@angular/core';
3
4@Component({...})
5export class MyComponent implements OnInit {
6
7  constructor(private activatedRoute: ActivatedRoute) {}
8
9  ngOnInit() {
10    // Note: Below 'queryParams' can be replaced with 'params' depending on your requirements
11    this.activatedRoute.queryParams.subscribe(params => {
12        const userId = params['userId'];
13        console.log(userId);
14      });
15  }
16
17}