get url params in typescript

The solution for “get url params in typescript” can be found here. The following code will assist you in solving the problem.

import {Router, ActivatedRoute, Params} from ‘@angular/router’;
import {OnInit, Component} from ‘@angular/core’;

export class MyComponent implements OnInit {

constructor(private activatedRoute: ActivatedRoute) {}

ngOnInit() {
// Note: Below ‘queryParams’ can be replaced with ‘params’ depending on your requirements
this.activatedRoute.queryParams.subscribe(params => {
const userId = params[‘userId’];


Thank you for using DeclareCode; We hope you were able to resolve the issue.

More questions on [categories-list]

inline scripts encapsulated in