경로에서 매개 변수를 가져 오는 데 문제가 있습니다. app.component.ts
에서 내가 @RouterConfig
을 정의하고있다 :Angular2 RouteParams가 매개 변수를 가져 오지 않습니다.
@RouteConfig([
...
{ path: '/companies', component: CompaniesListComponent, name: 'Companies' },
{ path: '/events/:nameId', component: EventsListComponent, name: 'Events'}
])
내부 것은 CompaniesListComponent
의 템플릿의 내가 가진하고있는 [routerLink]
다음
<a [routerLink]="['/Events', { 'nameId': company.nameId }]" class="btn btn-success col-md-offset-4">Show Events</a>
내가 위의 링크 위에 마우스를 명확하게 company.nameId
이 올바르게 설정되어 있는지 나를 보여줍니다 URL은 다음과 같습니다 : /events/cssmelbourne
, 여기서 cssmelbourne
은 nameId
입니다. 링크를 클릭 할 때 nameId is not defined
으로 인해 EventsListComponent
이로드되지 않습니다. 나는 다음과 같은 방법으로 nameId
매개 변수를 얻기 위해 노력하고 있어요 :
nameId: string = "";
constructor(private routeParams: RouteParams, private http: Http) {
this.nameId = routeParams.get('nameId');
}
나는 또한 this.nameId = routeParams.params['nameId'];
하지만 성공을 사용하려고했다.
당신은에 라우터를 연결 한 후 브라우저 URL 블록의 nameId을 볼 수 있습니다 '를 표시 이벤트' – mayur
내가 볼 가리키면 'nameId' 그리고 콘솔에서도. –
'nameId' 대신에'cssmelbourne'로 대체 된 값을 의미합니다. –