2017-03-15 86 views
1

我的路線定義爲:如何從ActivatedRoute(Angular2)獲得出口PARAMS

path: 'geooperations', 
    component: GeoMetricsComponent, 
    children: [ 
     { path: ':idgeooperationmetrictype', component: DetailGeoMetricTypeComponent, outlet: 'geo' }, 
     { path: ':idgeooperationmetrictype/edit', component: DetailGeoMetricTypeComponent, outlet: 'geo' }, 
     { path: '/new', component: DetailGeoMetricTypeComponent, outlet: 'geo' } 
    ] 

例子: 網址:geooperations /(GEO:c56da64c-0ef5-4894-83ee-04381​​8b44e14)

outlet : 'geo' 
idgeooperationmetrictype: 'c56da64c-0ef5-4894-83ee-043818b44e14' 

如何從ActivatedRoute獲得'idgeooperationmetrictype'?

回答

0

使用snapshot.params解決問題:

this.activatedRoute.snapshot.params.subscribe(params => {   
    console.log(params['idgeooperationmetrictype']); 
}); 
0

您需要在PARAMS線訂閱它的組成部分「DetailGeoMetricTypeComponent」

ngOnInit() { 
    this.sub = this.route.params.subscribe(params => { 
     this.id = params['idgeooperationmetrictype']; 
    }); 
    } 

或者設置斷點內與開發工具,以看清按鍵。

+0

第一個答案沒有工作。但是,我可以通過this.activatedRoute.url._value [0] .path獲取'idgeooperationmetrictype'。我不知道這是否可行,或者有另一種方法通過outlet params來完成它? –

+0

'activatedRoute.snapshot.params'做了個招數。 –