Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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();
  }

}
like image 403
Ryan Avatar asked Apr 02 '20 02:04

Ryan


1 Answers

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();
like image 94
xinthose Avatar answered Nov 15 '22 04:11

xinthose