当我稍后使用 `tap` 方法时,不会调用 `map`。我从点击中得到 return
When I use `tap` method later the `map` is not called. i get return from tap
我在 map
之前对 tap
的响应进行了一些更正,但在 tap
实施之后我没有被称为 map
。 map
一点也不安慰我。
在我们发送给 map
任何人帮助我之前,在回复中进行一些更正的最佳方法是什么?
同时让我知道 tap
的确切用法。
这是我的代码:
createTranslationId(translationId: ModelTranslationId) {
console.log('translationId', translationId);
return this.http.post<any>(environment.configUrl + `Configuration`, translationId)
.pipe(
tap(response => {
return Object.assign({}, response, {
Response: {
'Name': response.Response.Name,
'Description': response.Response.Description,
'TypeId': response.Response.TypeId,
'Type': response.Response.Type,
'Id': response.Response.Id,
'CreatedBy': response.Response.CreatedBy,
'CreatedDate': response.Response.CreatedDate,
'UpdatedBy': response.Response.UpdatedBy,
'UpdatedDate': response.Response.UpdatedDate
}
});
}),
map(response => {
console.log('response3', response);
return response;
}),
catchError(this.handleError)
);
}
提前致谢。
map()
是您想要的运算符来转换从网络到达的响应。参见 map operator doc。
tap()
只是根据响应做一些操作。它不会修改现有的响应,所以在 tap 表达式中返回一些东西是没有意义的。参见 tap operator doc
由于 tap 对镜像 Observable 执行操作,因此您无法对源进行修改,为此您需要使用 map 运算符
因此您可以按如下方式更改函数:
createTranslationId(translationId: ModelTranslationId) {
return this.http.post<any>(environment.configUrl + `Configuration`, translationId)
.pipe(map(response => {
response = // Your object modifications
}),
// Other pipe operators
);
}
我在 map
之前对 tap
的响应进行了一些更正,但在 tap
实施之后我没有被称为 map
。 map
一点也不安慰我。
在我们发送给 map
任何人帮助我之前,在回复中进行一些更正的最佳方法是什么?
同时让我知道 tap
的确切用法。
这是我的代码:
createTranslationId(translationId: ModelTranslationId) {
console.log('translationId', translationId);
return this.http.post<any>(environment.configUrl + `Configuration`, translationId)
.pipe(
tap(response => {
return Object.assign({}, response, {
Response: {
'Name': response.Response.Name,
'Description': response.Response.Description,
'TypeId': response.Response.TypeId,
'Type': response.Response.Type,
'Id': response.Response.Id,
'CreatedBy': response.Response.CreatedBy,
'CreatedDate': response.Response.CreatedDate,
'UpdatedBy': response.Response.UpdatedBy,
'UpdatedDate': response.Response.UpdatedDate
}
});
}),
map(response => {
console.log('response3', response);
return response;
}),
catchError(this.handleError)
);
}
提前致谢。
map()
是您想要的运算符来转换从网络到达的响应。参见 map operator doc。
tap()
只是根据响应做一些操作。它不会修改现有的响应,所以在 tap 表达式中返回一些东西是没有意义的。参见 tap operator doc
由于 tap 对镜像 Observable 执行操作,因此您无法对源进行修改,为此您需要使用 map 运算符
因此您可以按如下方式更改函数:
createTranslationId(translationId: ModelTranslationId) {
return this.http.post<any>(environment.configUrl + `Configuration`, translationId)
.pipe(map(response => {
response = // Your object modifications
}),
// Other pipe operators
);
}