【发布时间】:2017-05-25 01:07:22
【问题描述】:
我知道如何在嵌套组件之间传递数据。但是我有一个从 REST API 获取一些数据的服务。当我单击并运行函数时,我需要更改服务中的 URL。我需要将 ID 传递给我的服务并更改我的 URL。
我是我的组件:
showUnitDetails(selectedUnit) {
this.unitId = selectedUnit;
this.unitDetails = true;
this._unitService.getUnit(this.unitId).subscribe(resUnitData => this.unit = resUnitData, err => alert('Error'));
}
在我的服务中:
getUnit(id: unitId){
return this._http.get(this._url).map((response: Response) => response.json());
}
但是当我保存我的服务时,我收到了错误"Cannot find name unitId"。
【问题讨论】:
-
您应该将您的代码展示给您迄今为止尝试过的内容,否则唯一可以给出的建议是:使用参数。
-
自行删除帖子。
标签: angular rest angular-services