티스토리 뷰
반응형
Angular Router는 Angular의 핵심기능 중 하나인데 여기서 파라미터를 보내는 방법을 작성하겠다.
라우터를 선언하는 부분은 다음과 같이 가정하고
{ path: 'move/:param', component: MoveComponent },
하면 template나 component에서는 다음과 같이 사용할 것이다.
template
<a [routerLink]="['/move', param]"> 이라하고 param값을 넣어주면 :param에 값이 전달되는 식이다.
<a routerLink="/move/:param">
component
this.router.navigate(['/move', param]);
그리고 받는쪽에서는 다음과 같이 사용할 것이다. (여러가지 방법이 있음 )
// 방법1
this.activatedRoute.params.subscribe(
params => {
this.sq = params['param'];
}
);
// 방법2
// this.activatedRoute.
// .subscribe(params => this.sq = +params.get('param'));
// 방법3
this.sq = +this.activatedRoute.snapshot.paramMap.get('param');
이런식으로 주고받는데 이런식으로 보내게 된다면 라우트를 할 때 url에 파라미터가 노출이 되는 단점이 있다.
예를들어 위의 소스는 아래의 url처럼 될 것이다
http://localhost:8080/move/34
이것은 일방적인 파라미터를 주고받는 과정이고 쿼리 파라미터를 보낼 때는 또 다르다.
쿼리파람 관련글은 다음에 작성하겠다.
참조 : https://angular-2-training-book.rangle.io/handout/routing/query_params.html
반응형
'FrontEnd > Angular' 카테고리의 다른 글
양방향 바인딩 한글 짤리는 문제 (0) | 2018.07.10 |
---|---|
Angular Security - Sanitization (0) | 2018.07.09 |
라우터 새로고침 (0) | 2018.06.26 |
Angular select (0) | 2018.06.22 |
angular style (0) | 2018.06.18 |
공지사항
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
링크
TAG
- Spring Boot
- react
- JSON
- python3
- Router
- 페이스북 로그인
- data grid component
- JavaScript
- React-router
- 파이썬3
- data gird component
- MySQL
- data table component
- mobx
- data component
- localStorage
- angular router
- CSS
- Spring
- facebook login
- data component module
- Java
- 파이썬
- https://www.tistory.com/auth/logout/
- jQuery
- JPA
- Redux
- Python
- Angular
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 | 29 |
30 | 31 |
글 보관함