2016-07-15 47 views
3
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上有什么我可以用来解决这个问题的吗?事件是超类的类NaviagationEnd的,NavigationStart对于Angular2导航类型“事件”,Property'url'不存在导航EndEnd事件

+0

有你导入的事件形成@角/路由器。尝试移动控制台在if条件与条件如果(事件instanceof NavigationEnd) –

+0

你得到它!谢谢,林新这个打字稿的东西 – BathgateIO

+0

更新了这个答案。 –

回答

6

你必须import { Event } from @angular/router;。尝试使用条件将控制台移入if块。

this.subscription = this.router.events.subscribe((event:Event) => { 
    if(event instanceof NavigationEnd){ 
    console.log(event.url); 
    } 
}); 
+0

谢谢,这正是我想要过滤特定事件。 –