Angular ';过滤器';不存在于类型';可观察<;事件>';。我如何解决这个问题?

Angular ';过滤器';不存在于类型';可观察<;事件>';。我如何解决这个问题?,angular,typescript,Angular,Typescript,大家早上好 这是我的问题,我试图将一个模板集成到我的Angular项目中,但部分代码不起作用。filter函数似乎不再存在于可观察库中(从10更新到11?) 我试着使用pipe,但由于我不熟悉打字脚本和角度,我发现很难适应它 这是我的密码: 从'@angular/common'导入{DOCUMENT,Location}; 从“@angular/core”导入{Component,ElementRef,Inject,OnInit,Renderer2,ViewChild}; 从'@angular/R

大家早上好

这是我的问题,我试图将一个模板集成到我的Angular项目中,但部分代码不起作用。
filter
函数似乎不再存在于可观察库中(从10更新到11?)

我试着使用pipe,但由于我不熟悉打字脚本和角度,我发现很难适应它

这是我的密码:

从'@angular/common'导入{DOCUMENT,Location};
从“@angular/core”导入{Component,ElementRef,Inject,OnInit,Renderer2,ViewChild};
从'@angular/Router'导入{NavigationEnd,Router};
从“rxjs”导入{Subscription};
从“./common/navbar/navbar.component”导入{NavbarComponent};
@组成部分({
选择器:'应用程序根',
templateUrl:“./app.component.html”,
样式URL:['./app.component.scss']
})
导出类AppComponent实现OnInit{
专用路由器!:订阅;
@ViewChild(NavbarComponent)navbar!:NavbarComponent;
构造函数(私有呈现器:Renderer2,私有路由器:router,@Inject(DOCUMENT,)私有文档:any,私有元素:ElementRef,公共位置:location){}
恩戈尼尼特(){
var navbar=this.router.events.filter((事件:any)=>NavigationEnd的事件实例)。订阅((事件:NavigationEnd)=>{
如果(window.outerWidth>991){
window.document.children[0]。scrollTop=0;
}否则{
window.document.activeElement!.scrollTop=0;
}
this.navbar.sidebarClose();
this.renderer.listen('window','scroll',(event)=>{
常量编号=window.scrollY;
var_location=this.location.path();
_位置=_location.split('/')[2];
如果(数字>150 | | window.pageYOffset>150){
navbar.classList.remove('navbar-transparent');
}else if(_location!=“login”&&this.location.path()!=“nucleoicons”){
navbar.classList.add('navbar-transparent');
}
})
})
}
}
它应该可以帮助我管理导航栏,但当我运行项目时,会出现以下错误:

Error: src/app/app.component.ts:19:37 - error TS2339: Property 'filter' does not exist on type 'Observable<Event>'.
    
19     var navbar = this.router.events.filter((event:any) => event instanceof NavigationEnd).subscribe((event: NavigationEnd) => {
错误:src/app/app.component.ts:19:37-错误TS2339:类型“Observable”上不存在属性“filter”。
19 var navbar=this.router.events.filter((事件:any)=>NavigationEnd的事件实例)。订阅((事件:NavigationEnd)=>{
有人能帮我理解如何使它工作吗?如果我的代码有任何错误,请纠正我


感谢您的帮助!

您很可能已从RxJS v5升级到RxJS v6+。在此迁移过程中,应用运算符的方法已更改

RxJS v5

导入'rxjs/add/operator/filter';
this.router.events.filter((事件:any)=>NavigationEnd的事件实例)
RxJS v6+

从“rxjs/operators”导入{filter};
此为.router.events.pipe(
筛选器((事件:任意)=>NavigationEnd的事件实例)
)

请参阅详尽的迁移指南。

谢谢您,先生!如果有任何困难,我会查看链接并返回给您。