簡體   English   中英

類型“Observable”上不存在“finally”屬性<Object> &#39;

[英]Property 'finally' does not exist on type 'Observable<Object>'

我正在嘗試進行 spring 安全/角度登錄/注銷,但我不知道為什么 finally() 不被識別。 任何向前推進的幫助將不勝感激。 類型 'Observable' 上不存在屬性 'finally' 是錯誤。

import { Component } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { Router } from '@angular/router';
import 'rxjs/add/operator/finally';
import {UserService} from './user.service';
import 'rxjs/add/operator/catch';

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css']
})
export class AppComponent {
  constructor(private service: UserService, private http: HttpClient, private router: Router) {
    this.service.authenticate(undefined, undefined);
  }
  logout() {
    this.http.post('logout', {}).finally(() => {
      this.service.authenticated = false;
      this.router.navigateByUrl('/home');
    }).subscribe();
  }

}

我相信finallyrxjs 6+ 中的finalize替換

import { finalize } from "rxjs/operators";

this.http.post('logout', {}).pipe(
    finalize(() => {
        this.service.authenticated = false;
        this.router.navigateByUrl('/home');
    })).subscribe();

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM