1

我的路线定义为:

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

示例: URL:geooperations/(geo:c56da64c-0ef5-4894-83ee-04381​​8b44e14)

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

如何从 ActivatedRoute 获取“idgeooperationmetrictype”?

4

2 回答 2

1

您需要在组件“DetailGeoMetricTypeComponent”中订阅它

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

或者在 params 行使用开发工具设置断点以查看密钥。

于 2017-03-15T10:12:48.563 回答
-1

通过使用 snapshot.params 解决了这个问题:

this.activatedRoute.snapshot.params.subscribe(params => {           
   console.log(params['idgeooperationmetrictype']);
});
于 2017-03-15T10:42:13.890 回答