简体   繁体   中英

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. Any assistance moving forward would be greatly appreciated. Property 'finally' does not exist on type 'Observable' is the error.

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+

import { finalize } from "rxjs/operators";

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM