component get url params in component angular code example
Example 1: get url params angular
import { ActivatedRoute, Params } from '@angular/router';
@Component(...)
export class MyComponent implements OnInit {
constructor (private activatedRoute: ActivatedRoute){}
ngOnInit() {
this.activatedRoute.params.subscribe((params: Params) => {
if (params.myParam){
// Do something
}
});
}
}
Example 2: in angular how to get router url without query params
this.router.url.split('?')[0]