<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Ricardo Torres</title>
    <description>The latest articles on DEV Community by Ricardo Torres (@ricardojavister).</description>
    <link>https://dev.to/ricardojavister</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F884315%2Fdefe8155-b27e-4af8-a68e-f7c87474b949.jpeg</url>
      <title>DEV Community: Ricardo Torres</title>
      <link>https://dev.to/ricardojavister</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/ricardojavister"/>
    <language>en</language>
    <item>
      <title>Angular Forms</title>
      <dc:creator>Ricardo Torres</dc:creator>
      <pubDate>Wed, 29 Jun 2022 02:16:04 +0000</pubDate>
      <link>https://dev.to/ricardojavister/angular-forms-19l1</link>
      <guid>https://dev.to/ricardojavister/angular-forms-19l1</guid>
      <description>&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--fpcpwsB0--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://ricardo-torres.me/wp-content/uploads/2022/06/form-2.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--fpcpwsB0--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://ricardo-torres.me/wp-content/uploads/2022/06/form-2.png" width="729" height="349"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If you started learning Angular from version 1 (AngularJs), maybe you will be more familiarized with configuring a clean Html to handle states and validations in the form. This approach is known as &lt;strong&gt;Template-Driven Forms&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;In contrast Angular count with &lt;strong&gt;Model-Dirven Forms&lt;/strong&gt; or &lt;strong&gt;Reactive Forms&lt;/strong&gt; which delegates most of the responsability to apply validations and keep states (valid, invalid, touched and dirty) in the form over an object called FormControl located in the TypeScript and not in the HTML like the &lt;strong&gt;Template-Driven Forms&lt;/strong&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Template Driven Forms
&lt;/h2&gt;

&lt;p&gt;| &lt;strong&gt;Pros&lt;/strong&gt; | &lt;strong&gt;Cons&lt;/strong&gt; |&lt;br&gt;
| -Very easy to write | Require more lines of HTML code and it can turn it difficult to mantain. |&lt;br&gt;
| -Easy to read and understand | It &lt;strong&gt;can not&lt;/strong&gt; be tested, there is no way to apply unit test to their validators. |&lt;/p&gt;
&lt;h2&gt;
  
  
  Reactive Forms
&lt;/h2&gt;

&lt;p&gt;This powerful module provides a way to define a form as a &lt;strong&gt;FormGroup&lt;/strong&gt; in the TypeScript class to handle states and validations rules that will be associated to each input in the form throught a &lt;strong&gt;formControlName&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Personally, I think that both are good ways to create Forms in Angular, but your decision over one or another approach is up your needs, the complexity of the forms, if you must create smalls forms with a low complexity you can use Template-Driven Forms, but if you need to create complex forms with Unit test, Reactive Forms will be a smart decision.&lt;/p&gt;

&lt;p&gt;Let's create our first Reactive Form.&lt;/p&gt;

&lt;p&gt;Open your console and type:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;ng new reactive-forms
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;? Would you like to add Angular routing? (y/N) y
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--6ana4_Rk--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://ricardo-torres.me/wp-content/uploads/2022/06/new-project.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--6ana4_Rk--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://ricardo-torres.me/wp-content/uploads/2022/06/new-project.png" width="720" height="145"&gt;&lt;/a&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;cd reactive-forms
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;cd .\src\app
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Import the module ReactiveFormsModule in the app.module.ts&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import { CUSTOM_ELEMENTS_SCHEMA, NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { AppRoutingModule } from './app-routing.module';
import { AppComponent } from './app.component';
import { HeaderComponent } from './layout/header/header.component';
import { FooterComponent } from './layout/footer/footer.component';
import { HttpClientModule } from '@angular/common/http';
import { ReactiveFormsModule } from '@angular/forms';

@NgModule({
  declarations: [AppComponent, HeaderComponent, FooterComponent],
  imports: [BrowserModule, AppRoutingModule, HttpClientModule, ReactiveFormsModule],
  providers: [],
  bootstrap: [AppComponent],
  schemas: [CUSTOM_ELEMENTS_SCHEMA],
})
export class AppModule {}

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Create a folder inside app named components and create a component called create-fruits&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;ng g c create-fruits
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Define the structure of the Form in the class CreateFruitsComponent&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import { Component, OnInit } from '@angular/core';
import { FormControl, FormGroup, Validators } from '@angular/forms';
import { Record } from 'src/app/model/record';

@Component({
  selector: 'app-create-fruits',
  templateUrl: './create-fruits.component.html',
  styleUrls: ['./create-fruits.component.scss'],
})
export class CreateFruitsComponent implements OnInit {
  title!: string;
  form!: FormGroup;
  fruit!: Record;

  constructor() {}

  ngOnInit(): void {
    this.form = new FormGroup({
      name: new FormControl('', [Validators.required]),
      description: new FormControl('', [Validators.required]),
      image: new FormControl('', [Validators.required]),
      price: new FormControl(0, [Validators.required]),
    });
  }

  onSubmit(): void {
    console.log(this.form);
  }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;As I mentioned before, defining the form in the TypeScript provides a good way to handle the states of our form and all the formControls inside it.&lt;/p&gt;

&lt;p&gt;create-fruits.component.html&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;section class="section"&amp;gt;
  &amp;lt;div class="container"&amp;gt;
    &amp;lt;h1&amp;gt;New Fruit&amp;lt;/h1&amp;gt;
    &amp;lt;div class="form" [formGroup]="form" (ngSubmit)="onSubmit()"&amp;gt;
      &amp;lt;div class="form-group"&amp;gt;
        &amp;lt;label class="label"&amp;gt;Name :&amp;lt;/label&amp;gt;
        &amp;lt;input
          type="text"
          id="name"
          formControlName="name"
          placeholder="Name"
          class="input"
        /&amp;gt;
        &amp;lt;p
          class="help is-danger walkP"
          *ngIf="
            (form.controls['name'].dirty || form.controls['name'].touched) &amp;amp;&amp;amp;
            form.controls['name'].errors &amp;amp;&amp;amp;
            form.controls['name'].errors['required']
          "
        &amp;gt;
          Name is required!
        &amp;lt;/p&amp;gt;
      &amp;lt;/div&amp;gt;

      &amp;lt;div class="form-group"&amp;gt;
        &amp;lt;label class="label"&amp;gt;Description :&amp;lt;/label&amp;gt;
        &amp;lt;input
          type="text"
          id="description"
          formControlName="description"
          placeholder="Name"
          class="input"
        /&amp;gt;
        &amp;lt;p
          class="help is-danger walkP"
          *ngIf="
            (form.controls['description'].dirty ||
              form.controls['name'].touched) &amp;amp;&amp;amp;
            form.controls['description'].errors &amp;amp;&amp;amp;
            form.controls['description'].errors['required']
          "
        &amp;gt;
          Description is required!
        &amp;lt;/p&amp;gt;
      &amp;lt;/div&amp;gt;
      &amp;lt;div class="form-group"&amp;gt;
        &amp;lt;label class="label"&amp;gt;Image :&amp;lt;/label&amp;gt;
        &amp;lt;input
          type="text"
          id="image"
          formControlName="image"
          placeholder="Image"
          class="input"
        /&amp;gt;
        &amp;lt;p
          class="help is-danger walkP"
          *ngIf="
            (form.controls['image'].dirty || form.controls['name'].touched) &amp;amp;&amp;amp;
            form.controls['image'].errors &amp;amp;&amp;amp;
            form.controls['image'].errors['required']
          "
        &amp;gt;
          Image is required!
        &amp;lt;/p&amp;gt;
      &amp;lt;/div&amp;gt;
      &amp;lt;div class="form-group"&amp;gt;
        &amp;lt;label class="label"&amp;gt;Price :&amp;lt;/label&amp;gt;
        &amp;lt;input
          type="number"
          id="price"
          formControlName="price"
          placeholder="Price"
          class="input"
        /&amp;gt;
        &amp;lt;p
          class="help is-danger walkP"
          *ngIf="
            (form.controls['price'].dirty || form.controls['name'].touched) &amp;amp;&amp;amp;
            form.controls['price'].errors &amp;amp;&amp;amp;
            form.controls['price'].errors['required']
          "
        &amp;gt;
          Image is required!
        &amp;lt;/p&amp;gt;
      &amp;lt;/div&amp;gt;
      &amp;lt;div class="field is-grouped"&amp;gt;
        &amp;lt;div class="control"&amp;gt;
          &amp;lt;button
            type="submit"
            class="button is-success"
            (click)="onSubmit()"
            [disabled]="!form.valid"
          &amp;gt;
            Save
          &amp;lt;/button&amp;gt;
        &amp;lt;/div&amp;gt;
        &amp;lt;div class="control"&amp;gt;
          &amp;lt;button class="button is-warning"&amp;gt;Cancel&amp;lt;/button&amp;gt;
        &amp;lt;/div&amp;gt;
      &amp;lt;/div&amp;gt;
    &amp;lt;/div&amp;gt;
  &amp;lt;/div&amp;gt;
&amp;lt;/section&amp;gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Note that I am not using the classic tag form to encapsulate all my html elements, it is not necesary , because I am using a div with a [formGroup]="form" , additionally I am associating each input with its right formControl defined in the TypeScript.&lt;/p&gt;

&lt;p&gt;I hope that this post help you in your learning of Angular.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://ricardo-torres.net/demos/reactive-forms/#/"&gt;Live Demo&lt;/a&gt;&lt;br&gt;&lt;br&gt;
&lt;a href="https://github.com/ricardojavister/angular-demos-reactive-forms"&gt;Download Code&lt;/a&gt;&lt;/p&gt;

</description>
      <category>angular</category>
      <category>forms</category>
    </item>
    <item>
      <title>Components - Gallery of Fruits</title>
      <dc:creator>Ricardo Torres</dc:creator>
      <pubDate>Tue, 28 Jun 2022 19:30:24 +0000</pubDate>
      <link>https://dev.to/ricardojavister/components-gallery-of-fruits-3p1n</link>
      <guid>https://dev.to/ricardojavister/components-gallery-of-fruits-3p1n</guid>
      <description>&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;@Input&lt;/strong&gt; to send messages from Parent to Child&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;@Output&lt;/strong&gt; to send messages from Child to Parent&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--JDziL2Ju--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://ricardo-torres.me/wp-content/uploads/2022/06/gallery-of-fruits-1024x625.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--JDziL2Ju--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://ricardo-torres.me/wp-content/uploads/2022/06/gallery-of-fruits-1024x625.png" width="800" height="488"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Understand the concept of Communication between components is basic to develop any Application in angular.&lt;/p&gt;

&lt;p&gt;We must render a list of fruits by using 2 components:&lt;/p&gt;

&lt;p&gt;1- product-list&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;div class="container" id="navbar-container"&amp;gt;
  &amp;lt;section class="section"&amp;gt;
    &amp;lt;div class="container"&amp;gt;
      &amp;lt;div class="has-text-centered" id="services-text-container"&amp;gt;
        &amp;lt;h1 class="title is-1"&amp;gt;Gallery of Fruits&amp;lt;/h1&amp;gt;
      &amp;lt;/div&amp;gt;
      &amp;lt;br /&amp;gt;
      &amp;lt;div class="columns"&amp;gt;
        &amp;lt;app-product-card
          *ngFor="let item of record"
          [product]="item"
        &amp;gt;&amp;lt;/app-product-card&amp;gt;
      &amp;lt;/div&amp;gt;
    &amp;lt;/div&amp;gt;
  &amp;lt;/section&amp;gt;
&amp;lt;/div&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the component product-list, we must call the service productService to get the data.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import { Component, OnInit } from '@angular/core';
import { Record } from 'src/app/model/record';
import { ProductService } from 'src/app/services/product.service';

@Component({
  selector: 'app-product-list',
  templateUrl: './product-list.component.html',
  styleUrls: ['./product-list.component.scss'],
})
export class ProductListComponent implements OnInit {
  record: Record[] = [];
  constructor(private productService: ProductService) {}

  ngOnInit(): void {
    this.getProducts();
  }

  getProducts(): void {
    this.productService.getProducts().subscribe((data) =&amp;gt; {
      this.record = data.record;
    });
  }
}

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;2-product-card&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;div class="column"&amp;gt;
  &amp;lt;div class="card"&amp;gt;
    &amp;lt;div class="card-content"&amp;gt;
      &amp;lt;div class="has-text-centered"&amp;gt;
        &amp;lt;img [src]="product.image" /&amp;gt;
      &amp;lt;/div&amp;gt;
      &amp;lt;h3 class="title is-3 has-text-centered" id="card-product-description"&amp;gt;
        {{ product.name }}
      &amp;lt;/h3&amp;gt;
      &amp;lt;p class="has-text-centered"&amp;gt;
        {{ product.description }}
      &amp;lt;/p&amp;gt;
    &amp;lt;/div&amp;gt;
  &amp;lt;/div&amp;gt;
&amp;lt;/div&amp;gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the Typescript we must to define an &lt;strong&gt;@Input&lt;/strong&gt; property named product, it is going to receive the data from the parent component (product-list).&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import { Component, Input, OnInit } from '@angular/core';
import { Record } from 'src/app/model/record';

@Component({
  selector: 'app-product-card',
  templateUrl: './product-card.component.html',
  styleUrls: ['./product-card.component.scss'],
})
export class ProductCardComponent implements OnInit {
  @Input() product!: Record;
  constructor() {}

  ngOnInit(): void {}
}

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://ricardo-torres.net/demos/com-components/#/"&gt;Live Demo&lt;/a&gt;&lt;br&gt;&lt;br&gt;
&lt;a href="https://github.com/ricardojavister/angular-demos-com-components"&gt;Download Code&lt;/a&gt;&lt;/p&gt;

</description>
      <category>angular</category>
      <category>components</category>
    </item>
    <item>
      <title>Angular - Rxjs - Operator mergeAll</title>
      <dc:creator>Ricardo Torres</dc:creator>
      <pubDate>Tue, 28 Jun 2022 18:51:09 +0000</pubDate>
      <link>https://dev.to/ricardojavister/mergeall-28kl</link>
      <guid>https://dev.to/ricardojavister/mergeall-28kl</guid>
      <description>&lt;blockquote&gt;
&lt;p&gt;MergeAll is represented by 2 Observables, the first one is named a higher-order Observable and the second one is an Observable that will depend upon each item of the higher-order Observable.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;MergeAll is useful when you have a scenario to perform operations or searches by each item that is coming from the first Observable, so you are going to have one observable for each item.&lt;/p&gt;

&lt;p&gt;Let me illustrate this with an example to make it clear.&lt;/p&gt;

&lt;p&gt;Example:&lt;/p&gt;

&lt;p&gt;We have 2 Observables:&lt;/p&gt;

&lt;p&gt;1- I only have fruits names inside the the order higher Observable:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const fruits$ = new Observable((observer) =&amp;gt; {
      observer.next('Cereza');
      observer.next('Mandarina');
      observer.next('Pera');
      observer.complete();
    });
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;2-The second Observable contains all the fruits with name, description, price and its image, it is located in a service name productService:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;getProductsByName(name: string): Observable&amp;lt;any&amp;gt; {
    let headers = new HttpHeaders();
    headers = headers.set(
      'X-Master-Key',
      '$2b$10$ghNHmZWM5nvdrV5tDL6akuKN6JanJ9/iG9vAa4F1yJF8X/ccv3o9C'
    );
    const url = 'https://api.jsonbin.io/v3/b/62b9ef87192a674d291cb521';
    const data = this.httpClient.get&amp;lt;RootObject&amp;gt;(url, { headers: headers });
    return data.pipe(
      map((x) =&amp;gt; {
        return x.record;
      }),
      map((y) =&amp;gt; {
        let filtered = y.filter((c) =&amp;gt; c.name === name);
        return filtered.length &amp;gt; 0 ? filtered[0] : null;
      })
    );
  }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The challenge consist in reading the order higher observable and call the method getProductsbyName and searchs all the details for every product in the list of the Observable and show it in a gallery.&lt;/p&gt;

&lt;p&gt;Final Result:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--LbqC3zO4--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://ricardo-torres.me/wp-content/uploads/2022/06/frutis-1024x562.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--LbqC3zO4--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://ricardo-torres.me/wp-content/uploads/2022/06/frutis-1024x562.png" width="800" height="439"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Structure of the Observable with MergeAll.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--lyMLbc2y--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://ricardo-torres.me/wp-content/uploads/2022/06/mergeAll.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--lyMLbc2y--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://ricardo-torres.me/wp-content/uploads/2022/06/mergeAll.png" width="485" height="198"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Final Code:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import { Component, OnInit } from '@angular/core';
import { map, mergeAll, Observable, of } from 'rxjs';
import { Record } from 'src/app/model/record';
import { ProductService } from 'src/app/services/product.service';

@Component({
  selector: 'app-product-list',
  templateUrl: './product-list.component.html',
  styleUrls: ['./product-list.component.scss'],
})
export class ProductListComponent implements OnInit {
  record: Record[] = [];
  constructor(private productService: ProductService) {}

  ngOnInit(): void {
    this.getProducts();
  }

  addItem(name: string) {}

  getProducts(): void {
    const fruits$ = new Observable((observer) =&amp;gt; {
      observer.next('Cereza');
      observer.next('Mandarina');
      observer.next('Pera');
      observer.complete();
    });

    fruits$
      .pipe(
        map((x) =&amp;gt; {
          return this.productService.getProductsByName(`${x}`);
        }),
        mergeAll()
      )
      .subscribe((x) =&amp;gt; {
        this.record.push(x);
      });
  }
}

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://ricardo-torres.net/demos/mergeall/#/"&gt;Live Demo&lt;/a&gt;&lt;br&gt;&lt;br&gt;
&lt;a href="https://github.com/ricardojavister/angular-demos-mergeall"&gt;Download Code&lt;/a&gt;&lt;/p&gt;

</description>
      <category>angular</category>
      <category>operators</category>
      <category>reactiveprogramming</category>
    </item>
    <item>
      <title>Angular - Rxjs - Operator map</title>
      <dc:creator>Ricardo Torres</dc:creator>
      <pubDate>Mon, 27 Jun 2022 18:26:56 +0000</pubDate>
      <link>https://dev.to/ricardojavister/angular-rxjs-operator-map-3nam</link>
      <guid>https://dev.to/ricardojavister/angular-rxjs-operator-map-3nam</guid>
      <description>&lt;blockquote&gt;
&lt;p&gt;Transforms each item from an source by using a projection function and emit a result as an observable.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Let me show you an example:&lt;/p&gt;

&lt;p&gt;I created an Api in &lt;a href="https://jsonbin.io/"&gt;jsonbin.io&lt;/a&gt; and it is returning this json:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{
    "record": [
        {
            "name": "Pineapple",
            "description": "There are many variations of passages of Lorem.",
            "price": 650,
            "image": "https://images.unsplash.com/photo-1587883012610-e3df17d41270?ixlib=rb-1.2.1&amp;amp;ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&amp;amp;auto=format&amp;amp;fit=crop&amp;amp;w=687&amp;amp;q=80"
        },
        {
            "name": "Orange",
            "description": "There are many variations of passages of Lorem.",
            "price": 350,
            "image": "https://images.unsplash.com/photo-1577234286642-fc512a5f8f11?ixlib=rb-1.2.1&amp;amp;ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&amp;amp;auto=format&amp;amp;fit=crop&amp;amp;w=735&amp;amp;q=80"
        },
        {
            "name": "Grapes",
            "description": "There are many variations of passages of Lorem.",
            "price": 120,
            "image": "https://images.unsplash.com/photo-1577069861033-55d04cec4ef5?ixlib=rb-1.2.1&amp;amp;ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&amp;amp;auto=format&amp;amp;fit=crop&amp;amp;w=764&amp;amp;q=80"
        },
        {
            "name": "Morron",
            "description": "There are many variations of passages of Lorem.",
            "price": 75,
            "image": "https://images.unsplash.com/photo-1525607551316-4a8e16d1f9ba?ixlib=rb-1.2.1&amp;amp;ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&amp;amp;auto=format&amp;amp;fit=crop&amp;amp;w=710&amp;amp;q=80"
        },
    ],
    "metadata": {
        "id": "62b9ef87192a674d291cb521",
        "private": true,
        "createdAt": "2022-06-27T17:57:27.165Z"
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Firts, I show all the products at the left side and when the user clicks over an specific product, it will map the product selected at the right side.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--spcc71uJ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_800/https://ricardo-torres.me/wp-content/uploads/2022/06/map-1024x704.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--spcc71uJ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_800/https://ricardo-torres.me/wp-content/uploads/2022/06/map-1024x704.gif" width="800" height="550"&gt;&lt;/a&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import { Component, OnInit } from '@angular/core';
import { map } from 'rxjs';
import { Record } from 'src/app/model/record';
import { ProductService } from 'src/app/services/product.service';

@Component({
  selector: 'app-operator-map',
  templateUrl: './operator-map.component.html',
  styleUrls: ['./operator-map.component.scss'],
})
export class OperatorMapComponent implements OnInit {
  records: Record[] = [];
  record!: Record;
  constructor(private productService: ProductService) {}

  ngOnInit(): void {
    this.getProducts();
  }

  getProducts(): void {
    this.productService.getProducts().subscribe((data) =&amp;gt; {
      this.records = data.record;
    });
  }

  mapRecord(value: number) {
    this.productService
      .getProducts()
      .pipe(map((x) =&amp;gt; x.record))
      .subscribe((data) =&amp;gt; {
        this.record = data[value];
      });
  }
}

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://ricardo-torres.net/demos/map/#/"&gt;Live Demo&lt;/a&gt;&lt;br&gt;
&lt;a href="https://github.com/ricardojavister/angular-demos-map"&gt;Download Code&lt;/a&gt;&lt;/p&gt;

</description>
      <category>angular</category>
      <category>operators</category>
      <category>reactiveprogramming</category>
    </item>
  </channel>
</rss>
