【问题标题】:error TS2339: Property 'filter' does not exist on type 'Observable<Event>'错误 TS2339:“Observable<Event>”类型上不存在属性“过滤器”
【发布时间】:2019-03-02 19:39:46
【问题描述】:

我的应用出现错误 错误 TS2339:“可观察”类型上不存在属性“过滤器” 我试图导入各种东西,但没有奏效。 我的组件 ts 文件

import { Component, OnInit } from '@angular/core';
  import {
  Router,
  ActivatedRoute,
  NavigationEnd,
  Params,
  PRIMARY_OUTLET
} from '@angular/router';
import 'rxjs/add/operator/filter';

  ngOnInit() {
    const ROUTE_DATA_BREADCRUMB: string = 'breadcrumb';
    //subscribe to the NavigationEnd event
    this.router.events
      .filter(event => event instanceof NavigationEnd)
      .subscribe(event => {
        //set breadcrumbs
        let root: ActivatedRoute = this.activatedRoute.root;
        this.breadcrumbs = this.getBreadcrumbs(root);
        console.log(this.breadcrumbs);
      });
  }

我的 package.json

  "dependencies": {
    "@agm/core": "^1.0.0-beta.5",
    "@angular/animations": "^6.1.8",
    "@angular/common": "^6.0.3",
    "@angular/compiler": "^6.0.3",
    "@angular/core": "^6.0.3",
    "@angular/forms": "^6.0.3",
    "@angular/http": "^6.0.3",
    "@angular/platform-browser": "^6.0.3",
    "@angular/platform-browser-dynamic": "^6.0.3",
    "@angular/router": "^6.0.3",
    "bootstrap3": "^3.3.5",
    "core-js": "^2.5.4",
    "jquery": "^3.3.1",
    "rxjs": "^6.0.0",
    "zone.js": "^0.8.26"
  },

我不知道出了什么问题,但收到此错误 错误 TS2339:“可观察”类型上不存在属性“过滤器”

【问题讨论】:

    标签: rxjs angular6


    【解决方案1】:

    愚蠢的错误只需要管道

    ngOnInit() {
        this.router.events.pipe(
            filter(event => event instanceof NavigationEnd)
        ).subscribe(event => {
        //set breadcrumbs
        let root: ActivatedRoute = this.activatedRoute.root;
        this.breadcrumbs = this.getBreadcrumbs(root);
        console.log(this.breadcrumbs);
      });
    }
    

    并导入

    import { filter } from 'rxjs/operators';
    

    【讨论】:

      猜你喜欢
      • 2021-06-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-10-29
      • 2018-10-25
      • 2018-11-03
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多