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’;

@Component({…})
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’];
console.log(userId);
});
}

}

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

More questions on [categories-list]

0
inline scripts encapsulated in