“Observable<Object>”类型上不存在“finally”属性

Rya*_*yan 5 spring spring-security angularjs spring-boot angular

我正在尝试进行 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();
  }

}
Run Code Online (Sandbox Code Playgroud)

xin*_*ose 12

我相信在6+ 中finally被替换finalizerxjs

import { finalize } from "rxjs/operators";

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