我得到了一个Angular2服务,该服务应该从如下URL返回参数
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;
}
}
但当我调用服务的getParameter()方法时,我得到了错误:
error TS2339: Property 'foobar' does not exist on type '{ [key: string]: any; }'
出错后返回正确的结果。我可以使用调试器访问foobar参数,而不会出现任何问题。有人有类似的问题吗?我可以想象它被提前调用了?
(可能重复:
angular2 rc6: Property queryParams does not exist on type RouterState
)