Rxjs〜6.4.0 in Angular8。地图问题

问题描述 投票:0回答:2

我将我的应用程序更新为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);
angular rxjs
2个回答
1
投票

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

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

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

0
投票

您正在正确使用/导入它import { map } from 'rxjs/operators'

您能否提供有关实施的详细信息

checkUser(电子邮件)

梅托德?

如果返回承诺,请使用from()使它可观察。

导入“ of”的正确方法是

import { of } from 'rxjs';
© www.soinside.com 2019 - 2024. All rights reserved.