Reputation: 515
I am getting error in my app error TS2339: Property 'filter' does not exist on type 'Observable' I tried to import vaeious things but it didn't worked. My component ts file
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);
});
}
My 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"
},
I don't know whats wrong but getting this error error TS2339: Property 'filter' does not exist on type 'Observable'
Upvotes: 4
Views: 4998
Reputation: 515
Silly mistake just need to pipe
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);
});
}
and import
import { filter } from 'rxjs/operators';
Upvotes: 6