错误TS2339:类型“ Observable <事件>”上不存在属性“过滤器”

时间:2018-09-27 00:20:06

标签: rxjs angular6

我的应用出现错误 错误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:“可观察”类型上不存在属性“过滤器”

1 个答案:

答案 0 :(得分:4)

愚蠢的错误只需要管道

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';