[英]Property 'finally' does not exist on type 'Observable<Object>'
我正在尝试进行 spring 安全/角度登录/注销,但我不知道为什么 finally() 不被识别。 任何向前推进的帮助将不胜感激。 类型 '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();
}
}
我相信finally
被rxjs
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.