반응형
Angular2에서 다중 경로 매개변수 전달
아래와 같은 경로 매개변수를 여러 개 통과할 수 있습니까?id1
그리고.id2
에게component B
@RouteConfig([
{path: '/component/:id :id2',name: 'MyCompB', component:MyCompB }
])
export class MyCompA {
onClick(){
this._router.navigate( ['MyCompB', {id: "someId", id2: "another ID"}]);
}
}
OK 실수를 깨달았어요..그래야 한다./:id/:id2
어쨌든 이것은 튜토리얼이나 다른 StackOverflow 질문에서 발견되지 않았습니다.
@RouteConfig([{path: '/component/:id/:id2',name: 'MyCompB', component:MyCompB}])
export class MyCompA {
onClick(){
this._router.navigate( ['MyCompB', {id: "someId", id2: "another ID"}]);
}
}
이 답변에서 자세히 설명했듯이 mayur & user 3869623의 답변은 이제 사용되지 않는 라우터와 관련이 있습니다.이제 다음과 같이 여러 파라미터를 전달할 수 있습니다.
라우터를 호출하는 방법:
this.router.navigate(['/myUrlPath', "someId", "another ID"]);
routes.ts에서:
{ path: 'myUrlpath/:id1/:id2', component: componentToGoTo},
Angular에서 다중 경로 매개변수를 전달하는 두 가지 방법
방법-1
app.module.ts에서
경로를 구성요소2로 설정합니다.
imports: [
RouterModule.forRoot(
[ {path: 'component2/:id1/:id2', component: MyComp2}])
]
라우터를 호출하여 다중 매개변수 id1 및 id2가 있는 MyComp2로 이동합니다.
export class MyComp1 {
onClick(){
this._router.navigate( ['component2', "id1","id2"]);
}
}
방법-2
app.module.ts에서
경로를 구성요소2로 설정합니다.
imports: [
RouterModule.forRoot(
[ {path: 'component2', component: MyComp2}])
]
라우터를 호출하여 다중 매개변수 id1 및 id2가 있는 MyComp2로 이동합니다.
export class MyComp1 {
onClick(){
this._router.navigate( ['component2', {id1: "id1 Value", id2:
"id2 Value"}]);
}
}
new AsyncRoute({path: '/demo/:demoKey1/:demoKey2', loader: () => {
return System.import('app/modules/demo/demo').then(m =>m.demoComponent);
}, name: 'demoPage'}),
export class demoComponent {
onClick(){
this._router.navigate( ['/demoPage', {demoKey1: "123", demoKey2: "234"}]);
}
}
언급URL : https://stackoverflow.com/questions/36320821/passing-multiple-route-params-in-angular2
반응형
'programing' 카테고리의 다른 글
소켓 listen() backlog 매개 변수의 값을 결정하는 방법은 무엇입니까? (0) | 2023.08.20 |
---|---|
12c에서 utl_http &wallet 사용: 인증서 유효성 검사 실패 (0) | 2023.08.20 |
Sublime Text와 같이 PyCharm에서 선택한 텍스트를 둘러싸는 방법 (0) | 2023.08.20 |
jQuery로 내부 텍스트를 변경하려면 어떻게 해야 합니까? (0) | 2023.08.20 |
다른 테이블에 조건이 있는 테이블의 왼쪽 조인 (0) | 2023.08.20 |