Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/32.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 角度-.publishLast不是一个函数_Javascript_Angular_Rxjs - Fatal编程技术网

Javascript 角度-.publishLast不是一个函数

Javascript 角度-.publishLast不是一个函数,javascript,angular,rxjs,Javascript,Angular,Rxjs,我试图避免在使用async管道时创建多个请求。 我有以下请求从api获取用户 getUser(){ this.\u user=this.http.get(environment.baseapirl+'user') .烟斗( 点击((用户:用户)=>{ //如果响应中有jwt令牌,则登录成功 console.log(用户); 此.setIsVerified(用户.verified); this.userReady=true; }), catchError((错误:HttpErrorRespons

我试图避免在使用
async
管道时创建多个请求。 我有以下请求从api获取用户

getUser(){
this.\u user=this.http.get(environment.baseapirl+'user')
.烟斗(
点击((用户:用户)=>{
//如果响应中有jwt令牌,则登录成功
console.log(用户);
此.setIsVerified(用户.verified);
this.userReady=true;
}),
catchError((错误:HttpErrorResponse)=>{
console.log(error.statusText);
如果(error.status==403){
此参数为.logout();
}
返回投掷器(error.error);
}
))
.publishLast()
.refCount();;

}
从RxJS v6.x开始,您需要将
publishLast()
作为
管道的参数(参数),如下所示:

 getUser() {
      this._user = this.http.get<User>(environment.baseAPIUrl + 'user')
        .pipe(
          tap((user: User) => {
            // login successful if there's a jwt token in the response
            console.log(user);

            this.setIsVerified(user.verified);
            this.userReady = true;
          }),
          catchError((error: HttpErrorResponse) => {
              console.log(error.statusText);
              if (error.status === 403) {
                this.logout();
              }

              return throwError(error.error);
            }
          ),
          publishLast()
        )

        .refCount();;
    }
getUser(){
this.\u user=this.http.get(environment.baseapirl+'user')
.烟斗(
点击((用户:用户)=>{
//如果响应中有jwt令牌,则登录成功
console.log(用户);
此.setIsVerified(用户.verified);
this.userReady=true;
}),
catchError((错误:HttpErrorResponse)=>{
console.log(error.statusText);
如果(error.status==403){
此参数为.logout();
}
返回投掷器(error.error);
}
),
最后出版()
)
.refCount();;
}

您不应该像在RxJS v5.0中那样链接
publishLast()

您的意思是什么,对不起?RxJS的哪个版本?“RxJS”:“^6.1.0”操作符进入
管道()
,请参见“是”,它可以工作,谢谢。但是我还必须添加
refCount()
作为
pipe
的参数,这正常吗?是的,refCount()会在订阅者来来去去时自动订阅和取消订阅。如果要避免使用refCount(),可以使用shareReplay(1)而不是publishLast()。请更新您的答复,
refCount()应该是
.pipe(refCount())