ritz078 ritz078 - 2 months ago 12
Javascript Question

Property 'filter' does not exist on type 'Observable<Event>'

Hi I am using Angular 2 final with router 3.0. I want to filter the events that are emitted from

this.router.events


What I want to do :

import 'rxjs/operator/filter';

//...

this.router.events
.filter((event:Event) => event instanceof NavigationEnd)
.subscribe(x => console.log(x))


event
can be instanceOf
NavigationEnd
,
NavigationStart
or
RoutesRecognized
but I want only
NavigationEnd
. But I get an error that

Property 'filter' does not exist on type Observable<Event>


during compile time.

When i import the whole
rxjs
library the error disappears. What should I import to make it work without loading the full rxjs library ?

Answer

try using import 'rxjs/add/operator/filter';