Accessing Angular2 Query Paramters

You can quickly access query parameters in Angular2 by using the Router module from Angular/Router in your components.

import { Router } from '@angular/router';
...
export class FooBar {
construction(private router: Router){}
ngOnInit(){
let foo = this.router.routerState.snapshot.queryParams["foo"];
}
}

You can also subscribe to the queryParams property.

this.sub = this.router.routerState.queryParams
.subscribe(params =>
let bar = params["bar"];
);