From 96f5e7d74ad43f662a391c7b768869dd3787cb33 Mon Sep 17 00:00:00 2001 From: kabrunko-dev Date: Tue, 2 Jan 2024 18:25:50 -0300 Subject: [PATCH] refactor: improve code readability of challenge 38 --- .../rxjs/catch-error/src/app/app.component.ts | 26 ++++++++++--------- 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/apps/rxjs/catch-error/src/app/app.component.ts b/apps/rxjs/catch-error/src/app/app.component.ts index 6974c93..b6ac066 100644 --- a/apps/rxjs/catch-error/src/app/app.component.ts +++ b/apps/rxjs/catch-error/src/app/app.component.ts @@ -1,8 +1,8 @@ -import { Component, DestroyRef, inject } from '@angular/core'; import { CommonModule } from '@angular/common'; import { HttpClient } from '@angular/common/http'; -import { FormsModule } from '@angular/forms'; +import { Component, DestroyRef, OnInit, inject } from '@angular/core'; import { takeUntilDestroyed } from '@angular/core/rxjs-interop'; +import { FormsModule } from '@angular/forms'; import { Subject, concatMap, map } from 'rxjs'; @Component({ @@ -11,11 +11,11 @@ import { Subject, concatMap, map } from 'rxjs'; selector: 'app-root', template: `
- possible values: posts, comments, albums, photos, todos, users + + possible values: posts, comments, albums, photos, todos, users +
-
+ (); +export class AppComponent implements OnInit { + submit$ = new Subject(); input = ''; response: unknown; + private destroyRef = inject(DestroyRef); - constructor(private http: HttpClient) {} + private http = inject(HttpClient); + ngOnInit() { - this.submit$$ + this.submit$ .pipe( map(() => this.input), concatMap((value) => - this.http.get(`https://jsonplaceholder.typicode.com/${value}/1`) + this.http.get(`https://jsonplaceholder.typicode.com/${value}/1`), ), - takeUntilDestroyed(this.destroyRef) + takeUntilDestroyed(this.destroyRef), ) .subscribe({ next: (value) => {