gpt4 book ai didi

rxjs - 错误 TS2339 : Property 'filter' does not exist on type 'Observable'

转载 作者:行者123 更新时间:2023-12-04 16:06:48 24 4
gpt4 key购买 nike

我的应用程序出错
错误 TS2339:“可观察”类型上不存在属性“过滤器”
我试图导入 vaeious 的东西,但没有奏效。
我的组件 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:“可观察”类型上不存在属性“过滤器”

最佳答案

愚蠢的错误只需要管道

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

关于rxjs - 错误 TS2339 : Property 'filter' does not exist on type 'Observable<Event>' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52527682/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com