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



我正在尝试进行spring-security/angular登录/注销,但我找不到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();
}
}

rxjs6+中将finally替换为finalize

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

相关内容

最新更新