깜놀하는 해므찌로

Angular Observable subscirbe 본문

IT

Angular Observable subscirbe

agnusdei1207 2023. 4. 8. 02:33
반응형
SMALL
// 1번 사람의 정보를 받아 로그에 찍는 예시
this.http.get("https://swapi.dev/api/people/1")
    .subscribe(response => console.log(response));
// 원하는 데이터만 얻어내는 예시
this.http.get("https://swapi.dev/api/people/1")
    .pipe(map(response => ({
        name: response.name,
        birthYear: response.birth_year,
        height: Number(response.height),
        weight: Number(response.mass),
        eyeColor: response.eye_color
    })))
    .subscribe(luke => console.log(luke))

https://stackblitz.com/edit/mapping-rxjs-data?file=src%2Fapp%2Fapp.component.html 

 

Mapping Rxjs Data - StackBlitz

Starter project for Angular apps that exports to the Angular CLI

stackblitz.com

 

반응형
LIST

'IT' 카테고리의 다른 글

Angular HTTP 통신 예시  (0) 2023.04.08
Angular Observable Operator  (0) 2023.04.08
typescript array delete by index 요소 1개 삭제 예시  (0) 2023.04.08
SPA Angular 구조 다이어그램  (0) 2023.04.07
Angular *ngFor index 활용 예시  (0) 2023.04.07