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();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With