<?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: hsminchala</title>
    <description>The latest articles on DEV Community by hsminchala (@hsminchala).</description>
    <link>https://dev.to/hsminchala</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%2F908774%2F8e5dde7e-fa9f-4c45-aa7f-40120f9c843c.png</url>
      <title>DEV Community: hsminchala</title>
      <link>https://dev.to/hsminchala</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/hsminchala"/>
    <language>en</language>
    <item>
      <title>Question - Add values from an array brought from firebase and display them in a label</title>
      <dc:creator>hsminchala</dc:creator>
      <pubDate>Sun, 14 Aug 2022 22:07:30 +0000</pubDate>
      <link>https://dev.to/hsminchala/question-add-values-from-an-array-brought-from-firebase-and-display-them-in-a-label-4jbf</link>
      <guid>https://dev.to/hsminchala/question-add-values-from-an-array-brought-from-firebase-and-display-them-in-a-label-4jbf</guid>
      <description>&lt;p&gt;I am doing my project in ionic 6 with angular and a firebase database. I need a typescript function that adds the values fetched from an array that are extracted from a collection in firebase.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;   async getGastos() {
        const uid = await this.auth.getUid();
        const ruta = 'Usuarios/' + uid + '/Gastos';
        this.firebaseService.getCollection&amp;lt;Gasto&amp;gt;(ruta).subscribe(res =&amp;gt; {
            this.gastos = res;
            // this.gastos.forEach(gasto =&amp;gt; {
            //     gasto.monto_gasto;
            // });
        });
        this.setTransc()
           }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;//Function to fetch the data from the "expenses" collection, the "expense_amount" column and add this data to the "setTransc" function&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    async getIngresos() {
        const uid = await this.auth.getUid();
        const ruta = 'Usuarios/' + uid + '/Ingresos';
        this.firebaseService.getCollection&amp;lt;Ingreso&amp;gt;(ruta).subscribe(res =&amp;gt; {
            this.ingresos = res;
            // this.ingresos.forEach(ingreso =&amp;gt; {
            //     ingreso.monto_ingreso
            // });
        this.setTransc()
        });
    }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;//Function to fetch the data from the "income" collection, the "expense_amount" column and add this data to the "setTransc" function&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    setTransc() {
        let sumaGastos = 0;
        this.gastos.forEach(gasto =&amp;gt; {
            sumaGastos += gasto.monto_gasto
            console.log("ggg", sumaGastos);
        });

        let sumaIngresos = 0;
        this.ingresos.forEach((ingreso, i) =&amp;gt; {
            sumaIngresos += ingreso.monto_ingreso
            console.log("iii", sumaIngresos);
        });
    }

    async todo(){
        await this.getGastos();
        await this.getIngresos();
    }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;"setTransc()" function to sum the values of the array, then the "todo()" function has an await since the elements return a promise before being displayed.&lt;/p&gt;

&lt;p&gt;It should be noted that I need to press a button for the values to be operated because I don't know how to do it in the background to show it directly in the next view.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--7zr7jyht--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/jguyv0xv07uxdazs5rdy.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--7zr7jyht--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/jguyv0xv07uxdazs5rdy.png" alt="Image description" width="880" height="470"&gt;&lt;/a&gt;&lt;br&gt;
Thanks in advance and sorry for my bad English.&lt;/p&gt;

</description>
      <category>typescript</category>
      <category>html</category>
      <category>firebase</category>
      <category>angular</category>
    </item>
  </channel>
</rss>
