我无法使用路由器从一个组件到下一个参数传递和激活路线Angular2快照参数/服务在角2
我EdmundsAPI服务返回楠:
getModels(makeNiceName: string): Observable<Models> {
return this.http.get(this.baseURL +
+ makeNiceName + '/models?year=2017&view=basic' + this.apiKey)
.map(res => res.json())
.catch(this.handleError);
}
我的“从'组分(使):
goToModels(makeNiceName: string): void {
this.router.navigate ([ '/models', { data: makeNiceName } ]);
}
我的 '到' 组分(型号):
(变量 'makeNiceName' 之后 '出口类' declar通货膨胀):从Models.getModels
makeNiceName: string = this.route.snapshot.params[ 'data' ];
getModels(): void {
this._EdmundsAPIService.getModels(this.makeNiceName)
.subscribe(
//Do Stuff here
error => this.errorMessage = <any>error);
}
我的API URL()(从浏览器Chrome的检查 - >网络):
的BaseURL + /NaN的/车型年= 2017年&视图=基本? + apiKey
为什么NaN的代替我“makeNiceName”变量,这是我想传递给我的服务做一个URL字符串被
尝试'this._EdmundsAPIService.getModels(makeNiceName)'insted的 – Jag
@Jag这是从ES6类的一个片段,这是行不通的因为这是必需的。 – Adam
您是否尝试过调试以确保'makeNiceName'是您期望的字符串? – Adam