get url parameters in angular code example
Example 1: angular get url param
constructor(private activatedRoute: ActivatedRoute) {
this.activatedRoute.queryParams.subscribe(params => {
let date = params['startdate'];
console.log(date);
});
}
Example 2: 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){
}
});
}
}