Issue
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();
}
}
Solution
finally
was replaced 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();
Answered By - xinthose
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.