【问题标题】:Property 'finally' does not exist on type 'Observable<Object>''Observable<Object>' 类型上不存在属性'finally'
【发布时间】:2020-07-13 22:47:32
【问题描述】:

我正在尝试进行弹簧安全/角度登录/注销,但我无法找出为什么 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();
  }

}

【问题讨论】:

    标签: angularjs angular spring spring-boot spring-security


    【解决方案1】:

    我相信finallyrxjs 6+ 中被finalize 替换

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

    【讨论】:

      猜你喜欢
      • 2018-06-25
      • 2019-03-16
      • 1970-01-01
      • 2019-02-04
      • 2018-11-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多