Angular2 NavigationEnd事件的类型“事件”上不存在属性“ URL” [英] Property 'url' does not exist on type 'Event' for Angular2 NavigationEnd Event
本文介绍了Angular2 NavigationEnd事件的类型“事件”上不存在属性“ URL”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
this.subscription = this.router.events.subscribe((event:Event) => {
console.log(event.url); ##### Error : Property 'url' does not exist on type 'Event'.
}
Typescript无法识别Angular Router内置的Event类型的属性。tsd上有什么我可以用来解决的问题吗?Event是NaviagationEnd,NavigationStart类的超类
Typescript doesn't recognize the properties of the type Event that is built into the Angular Router. Is there something on tsd that I can use to solve this? Event is the super class of classes NaviagationEnd, NavigationStart
推荐答案
您必须从@ angular / router导入{Event};
尝试将控制台移至 if
有条件的块。
You have to import { Event } from @angular/router;
. Try moving console into the if
block with condition.
this.subscription = this.router.events.subscribe((event:Event) => {
if(event instanceof NavigationEnd ){
console.log(event.url);
}
});
这篇关于Angular2 NavigationEnd事件的类型“事件”上不存在属性“ URL”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文