get params url 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){
}
});
}
}
Example 3: angular get url params
import { ActivatedRoute } from "@angular/router";
private $route: ActivatedRoute
this.$route.params.forEach(param =>
this.myvar = param['whatever your param name is']
);
Example 4: angular routing url params
const appRoutes: Routes = [
{ path: 'crisis-center/:param1', component: CrisisListComponent },
{ path: 'hero/:param2', component: HeroDetailComponent },
];
@NgModule({
imports: [
RouterModule.forRoot(
appRoutes,
{ enableTracing: true }
)
],
...
})
export class AppModule { }
Example 5: angular url parameter
constructor(private activatedRoute: ActivatedRoute) {
this.activatedRoute.queryParams.subscribe(params => {
console.log(params);
});
}