简体   繁体   English

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

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

I am attempting to make a spring security/angular login/logout and I cannot find out why finally() is not recognized.我正在尝试进行 spring 安全/角度登录/注销,但我不知道为什么 finally() 不被识别。 Any assistance moving forward would be greatly appreciated.任何向前推进的帮助将不胜感激。 Property 'finally' does not exist on type 'Observable' is the error.类型 '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();
  }

}

I believe finally was replace with finalize in rxjs 6+我相信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