Hi I am trying to extract the id part of the url using Angular2.
http://localhost:3000/item/187809
I have been playing around with ActiveRoute
I have faced the same problem while working with Angular 8, and solved it by:
At first, import ActivatedRoute:
import { ActivatedRoute } from '@angular/router';
Then, Inject ActivatedRoute in the constructor:
constructor(private activatedRoute: ActivatedRoute) {}
Your ngOnit method will look like this.
ngOnInit(){
const id = this.activatedRoute.snapshot.paramMap.get('id');
}
I found it from the official documentation of Angular.