I got an Angular2-service that should return parameters from an URL like http://localhost:3001/?foobar=1236
import { Injectable } from '@angular/core';
import { ActivatedRoute } from '@angular/router';
import 'rxjs/add/operator/map';
@Injectable()
export class ParameterService {
constructor(private route: ActivatedRoute) { }
getParameter() {
return this.route.snapshot.queryParams.foobar;
}
}
But when I call the getParameter() method of the service I get the error:
error TS2339: Property 'foobar' does not exist on type '{ [key: string]: any; }'
and after the error it returns the correct result. I can access the foobar parameter with the debugger without any problems. did someone had a similar issue? I could imagine that it gets called to early?
(possible duplicate: angular2 rc6: Property queryParams does not exist on type RouterState)
This is how you get parameters:
this.route.snapshot.queryParams['foobar'];
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With