【发布时间】:2019-12-18 13:17:35
【问题描述】:
我只是将我的应用程序从 Angular 7 升级到 Angular 8。 自迁移以来,我的一种方法似乎不再起作用。在 Observable 上(来自 HTTP POST),我想通过 .pipe() 执行一些操作。
调用者可以在返回的 Observable 上执行 .subscribe()。
login(username: string, password: string): Observable {
const url = `${this.baseUrl}/oauth/token`;
const body = `username=${encodeURIComponent(username)}&password=${encodeURIComponent(password)}&grant_type=password`;
return this.http.post(url, body, this.httpOptions)
.pipe( map(value => {
console.info('Succeed');
return of(true);
}));
}
不幸的是,地图似乎不再执行(控制台没有登录)。
有人帮我找到解决方法吗? 提前致谢。
【问题讨论】:
-
你试过加
.pipe(catchError((error: HttpErrorResponse) => {}吗? -
对了,你为什么要这么做?
-
是的,没有错误。调用者收到http请求的响应...
-
我的目的是执行一些操作并将 HTTP 响应转换为返回“格式化”值(而不是 HTTP 响应 OAUTH2)
标签: angular observable angular8