2017-02-24 58 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