首页 > 解决方案 > Rxjs ~6.4.0 in Angular 8. 地图问题

问题描述

我将我的应用程序更新到 Angular 8,并且有新版本的 rxjs ~6.4.0。现在我的 .map 功能不起作用,我在 VC 中有一个错误

“可观察”类型上不存在属性“地图”。

我尝试通过多种方式导入地图

import 'rxjs/add/operator/map';

或者这样

import { map } from 'rxjs/operators';

结果一样。下面的代码

canActivate(next: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<boolean> {
const email = this.userInfo.email;
return this.routApi.checkUser(email).map(e => {
  this.tradeOperService.writeOperRoomFromResponse(e);
  return true;
}).catch((e) => {
  if (e.error === 'traderoom') {
    this.router.navigate(['registration']);
  }
  if (e.status === 500) {
    this.authService.logout().subscribe(
      suc => {
        this.tokenService.deleteToken();
        this.tradeOperService.deleteOperRoomInfo();
        this.router.navigate(['login']);
      },
      err => {
        this.OperRoomService.deleteOperRoomInfo();
        this.tokenService.deleteToken();
      }
    );
  }
  return Observable.of(false);
});

错误如果在这里

return this.routApi.checkUser(email).map(e => {

代码末尾带有“of”的情况相同

return Observable.of(false);

标签: angularrxjs

解决方案


您现在需要使用管道链接运算符。改变这个:

return this.routApi.checkUser(email).map(e => {

return this.routApi.checkUser(email).pipe(
   map(e => {
   })
)

推荐阅读