这就是我现在拥有的:
cachedEntities: Map<string, CareerPreferenceMyCareer> = new Map<string, CareerPreferenceMyCareer>();
getByEmployeeId(employeeId: string): Observable<CareerPreferenceMyCareer> {
return this.http.get<CareerPreferenceMyCareer>(`${this.startupService.settings.coreUrl}/${this.serviceEndpoint}/ByEmployee/${employeeId}`).pipe(
map(res => {
if (res)
this.cachedEntities.set(employeeId, res); //I want to get exatly this object but map operator creates a new object
return this.cachedEntities.get(employeeId);
})
);
}
我知道由于map
管道运算符而创建了新对象,但是是否可以获取现有对象而不是新对象?也许和另一位接线员在一起?
我希望能很好地解释我的问题。在此先感谢您,如果我写错了任何错误,请纠正我
答案 0 :(得分:0)
不。地图操作员不会创建新对象。返回完全相同的对象。是您创建新对象的功能。查看示例:https://stackblitz.com/edit/angular-cezdgd