2017-02-24 110 views
0

我试图找到我的浏览器当前的URL和我做了下列当前路由器,如何获得angular2

import { Router, ActivatedRoute } from '@angular/router'; 

@Component({ 
    templateUrl: './app/profile/profile.html', 
}) 
export class Profile { 
    constructor(fbld: FormBuilder, public router: ActivatedRoute) { 
     console.log(router._routerState.snapshot.url) 
    } 

} 

,当我在我的浏览器“router._routerState.snapshot检查。网址“显示我的网址,但是当我把我的ts文件显示错误:”_routerState不是激活的路由器的一部分“,任何人都可以请帮助我。谢谢。

回答

0

为什么不能简单地使用

export class Profile { 
    constructor(fbld: FormBuilder, public router: Router) { 
     console.log(this.router.url,"Return full URL including params") 
} 

其中这里路由器是从Router