<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Qarun Qadir Bissoondial on Medium]]></title>
        <description><![CDATA[Stories by Qarun Qadir Bissoondial on Medium]]></description>
        <link>https://medium.com/@qarunqb?source=rss-f58cdda6891a------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/2*H5yu2bttXnI7aSiboDxOUA.jpeg</url>
            <title>Stories by Qarun Qadir Bissoondial on Medium</title>
            <link>https://medium.com/@qarunqb?source=rss-f58cdda6891a------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 30 Nov 2026 09:07:36 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@qarunqb/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Angular Modules — Basics]]></title>
            <link>https://qarunqb.medium.com/angular-modules-basics-5eabda9e8657?source=rss-f58cdda6891a------2</link>
            <guid isPermaLink="false">https://medium.com/p/5eabda9e8657</guid>
            <category><![CDATA[angular]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[angular-material]]></category>
            <dc:creator><![CDATA[Qarun Qadir Bissoondial]]></dc:creator>
            <pubDate>Sun, 13 Sep 2020 05:52:45 GMT</pubDate>
            <atom:updated>2020-11-07T09:28:48.456Z</atom:updated>
            <content:encoded><![CDATA[<h3>Angular Modules — Basics</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*w18KG2T-TlNN17mM.png" /></figure><p>Angular is a popular framework for building rich UIs and high-performance Web Applications. It’s also very opinionated in its code structure, meaning that the framework prefers things to be done “the angular way”. Part of this means including Angular Modules in your application/library. But what are modules exactly? 🤔🤔🤔</p><h3>Modules</h3><p>An Angular Module is simply a way to group individual pieces of logic and components together under one umbrella. Let’s take a look at the most common module that all Angular applications have: AppModule.</p><pre>import { NgModule } from &#39;@angular/core&#39;;<br>import { BrowserModule } from &#39;@angular/platform-browser&#39;;<br><br>import { AppComponent } from &#39;./app.component&#39;;<br><br>@NgModule({<br>  imports:      [ BrowserModule ],<br>  declarations: [ AppComponent ],<br>  providers: [],<br>  bootstrap:    [ AppComponent ]<br>})<br>export class AppModule { }</pre><p>There is an @NgModule decorator that tells Angular to prepare this class to be a Module.<br> The decorator accepts an object that customizes the module.</p><p>The bootstrap option is specific to AppModule since it specifies the entry point through which Angular loads the rest of the application.</p><p>The declarations array shows what this module contains. <em>Components, pipes and directives</em> are listed here and can be used within this module and can interact with each other. For example, if our AppModule was:</p><pre>@NgModule({<br>  imports:      [ BrowserModule ],<br>  declarations: [ AppComponent, TestOneComponent, TestTwoComponent],<br>  providers: [],<br>  bootstrap:    [ AppComponent ]<br>})<br>export class AppModule { }</pre><p>Then inside our app.component.html, we could have something like:</p><pre>&lt;app-test-one&gt; &lt;/app-test-one&gt;<br>&lt;app-test-two&gt; &lt;/app-test-two&gt;</pre><p>This is because these 2 components were declared in AppModule and therefore, were made available. Generally speaking, whatever we put in the declarations array of AppModule becomes globally available to use.</p><p>The imports and exports array tells us what other modules are connected to this one. It allows us to compose modules together like lego blocks. For example:</p><pre>@NgModule({<br>  imports:      [ CommonModule ],<br>  declarations: [ FirstComponent, SecondComponent ],<br>  providers: [],<br>  exports: [FirstComponent]<br>})<br>export class FirstModule { }<br><br>@NgModule({<br>  imports:      [ CommonModule, FirstModule ],<br>  declarations: [],<br>  providers: [],<br>})<br>export class SecondModule { }</pre><p>Usually these modules would be in different files but they are next to each other for the sake of example. We can see that:</p><ul><li>FirstModule exports a component called FirstComponent</li><li>SecondModule imports FirstModule. This means that FirstComponent is now available to use inside of SecondModule.</li></ul><p>We also see that FirstModule has another component called SecondComponent but it isn&#39;t exported. This means it can never be made available to other modules that import FirstModule.</p><p>The providers array allows us to inject default or replacement values, classes and more wherever it appears in code associated with our module. It&#39;s much clearer with an example.</p><p>Angular Material Components have many defaults but we can change those defaults using the providers array of the module where our Material Components are imported.</p><pre>@NgModule({<br>  imports:      [<br>    BrowserModule, <br>    BrowserAnimationsModule,<br>    MatExpansionModule<br>  ],<br>  declarations: [ AppComponent ],<br>  providers: [<br>     { <br>      provide: MAT_EXPANSION_PANEL_DEFAULT_OPTIONS,<br>      useValue: {<br>        collapsedHeight: &#39;64px&#39;,<br>        expandedHeight: &#39;80px&#39;<br>      }<br>    }<br>  ],<br>  bootstrap:    [ AppComponent ]<br>})<br>export class AppModule { }</pre><p>In the above example, we tell Angular Material to ignore the defaults set for &lt;mat-expansion-panel&gt; and apply the configuration that we provided. Remember that this will affect all expansion panels used in this module.</p><h3>Conclusion</h3><p>We covered what an Angular Module is and the basic parts that make up Angular Modules. Hopefully this article was helpful and that you understand modules just a little more.</p><p>There are lots of other topics to cover in Angular Modules and I aim to tackle them all. So stay tuned and thanks for reading! ❤️</p><p><em>Originally published at </em><a href="https://dev.to/qarunqb/angular-basics-intro-to-modules-11mj"><em>https://dev.to</em></a><em> on September 13, 2020.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5eabda9e8657" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Angular Material Handbook: Setup and Basics]]></title>
            <link>https://qarunqb.medium.com/angular-material-handbook-setup-and-basics-63edec96032c?source=rss-f58cdda6891a------2</link>
            <guid isPermaLink="false">https://medium.com/p/63edec96032c</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[angular]]></category>
            <category><![CDATA[angular-material]]></category>
            <dc:creator><![CDATA[Qarun Qadir Bissoondial]]></dc:creator>
            <pubDate>Sat, 30 May 2020 00:30:13 GMT</pubDate>
            <atom:updated>2020-11-07T09:13:04.198Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*hWpb1Cgu3OQtrYrD.png" /></figure><p>If you’re an Angular developer, chances are that you’ve heard of <a href="https://material.angular.io/">Angular Material</a>. If not, then that’s okay, I’m here to guide you.</p><p>Angular Material is a component library that follows the Google <a href="https://material.io/design/guidelines-overview">Material Design Spec</a>. Buttons, tabs, form fields and loading spinners are just a few of the many components in this library and it’s super easy to develop applications quickly.</p><p>My goal with this series is to walk through each and every single component and show you how to use it, take advantage of its API and customize them for your own applications. We will need to run through a few foundation concepts before hitting the components but I’ll try my best to keep it short and sweet. Let’s get started!</p><p><strong>Note that at the time of writing, I’m currently using Angular 9 with its corresponding Angular Material Version. I’ll try my best to update these articles as Angular updates.</strong></p><p><em>Hint: All the code for this article can be found </em><a href="https://github.com/Qarun-Qadir-Bissoondial/angular-material-tutorial/tree/1-setup-and-basic-concepts"><em>here</em></a><em>.</em></p><h3>Installation and Setup</h3><p>Create a new project by running ng new angular-material-tutorial and cd into the root directory of the project. Once inside, we need to run ng add @angular/material.</p><p>This will install the necessary npm modules and walks us through some default configuration options. Let’s walk through them.</p><h3>Themes</h3><p>The first question we need to answer is what theme we would like to pick.</p><pre>? Choose a prebuilt theme name, or &quot;custom&quot; for a custom theme: (Use arrow keys) ❯ Indigo/Pink [ Preview: https://material.angular.io?theme=indigo-pink ] Deep Purple/Amber [ Preview: https://material.angular.io?theme=deeppurple-amber ] Pink/Blue Grey [ Preview: https://material.angular.io?theme=pink-bluegrey ] Purple/Green [ Preview: https://material.angular.io?theme=purple-green ] Custom</pre><p>Pick any that you like, I’ll choose Indigo/Pink as my default. We’ll look at custom themes in a later article, I promise! But for now, I’ll link the previews below.</p><ul><li><a href="https://material.angular.io/?theme=indigo-pink">Indigo/Pink</a></li><li><a href="https://material.angular.io/?theme=deeppurple-amber">Deep Purple/Amber</a></li><li><a href="https://material.angular.io/?theme=pink-bluegrey">Pink/Blue Grey</a></li><li><a href="https://material.angular.io/?theme=purple-green">Purple/Green</a></li></ul><p>It’s important to pick a theme that matches the feel of your application or a theme that matches the brand of your company. But more importantly, we need to keep accessibility in mind. Angular Material Themes should all conform to the <a href="https://www.w3.org/WAI/standards-guidelines/wcag/">WCAG Standards</a>. These rules are laid out so that people who are differently-abled can still access our applications.</p><p>One example is maintaining an acceptable level of contrast between background and foreground to ensure visibility of content. This is also part of WCAG Compliance and should be adhered to. Failure to adhere to these rules can actually result in a lawsuit in some parts of the world!</p><h3>Angular Material Typography</h3><pre>? Choose a prebuilt theme name, or &quot;custom&quot; for a custom theme: Indigo/Pink [ Preview: https://material.angular.io?theme=indigo-pink ] ? Set up global Angular Material typography styles? (y/N) y</pre><p>Unless you have your own Typography System, you’ll want to select yes for this setting. This gives us access to a lot of classes responsible for spacing, shadows, animations, etc. By default, Angular Material does not apply any global CSS but these will be applied within components and to child elements of a parent bearing the .mat-typography class. You can find out more <a href="https://material.angular.io/guide/typography">here</a>.</p><h3>Browser Animations</h3><pre>Choose a prebuilt theme name, or &quot;custom&quot; for a custom theme: Indigo/Pink [ Preview: https://material.angular.io?theme=indigo-pink ] ? Set up global Angular Material typography styles? Yes ? Set up browser animations for Angular Material? (Y/n) y</pre><p>You’ll want to select yes for this one as well as most of Angular Material UX interactions rely on animations. It follows the <a href="https://material.io/design/motion/understanding-motion.html#principles">Material Design Guidelines on Motion</a>.</p><h3>Finishing Installation</h3><pre>UPDATE src/app/app.module.ts (502 bytes)<br>UPDATE angular.json (3972 bytes)<br>UPDATE src/index.html (526 bytes)<br>UPDATE src/styles.scss (181 bytes)</pre><p>At this point, the installation is complete and the above files have been altered. Here’s a brief summary:</p><ul><li>Material Design Icons and the Roboto Font (at font weights 300, 400 and 500) has been added to your index.html. You can add more of these weights if needed. Weights are in multiples of 100 and ranges 100-900. .mat-typography has also been applied to your body.</li><li>Default styles have been added to your styles.scss file</li><li>The .css theme that we selected earlier has been inserted into angular.json under the styles section of our application build and test configuration</li><li>package.json and package-lock.json were updated with the installed packages.</li></ul><p>Now we can run ng serve and open our browser on localhost:4200 to see our Angular Application. If you&#39;ve reached this far without any errors, then you&#39;ve sucessfully added Angular Material to your project 😄</p><h3>Templating Basics</h3><p>Angular gives us access to the properties of an HTML Element by allowing us to create a Template Reference. This reference can now be accessed directly by our HTML just like a component variable or inside the component itself using the @ViewChild decorator.</p><p>We won’t need to use @ViewChild unless necessary but I wanted to illustrate how to use Template Referencing to our advantage. It&#39;s also extremely vital knowledge to have when working with Angular Material.</p><p>Let’s say we have a counter component. This component starts at 0 and shows the number by default. We have the option to show, hide and increment the number. But we want parent components to control these actions. I used inline styles and template as the component was small.</p><pre>import { Component } from &#39;@angular/core&#39;;<br><br>@Component({<br>  selector: &#39;app-counter&#39;,<br>  template: `<br>  &lt;h2&gt;My Counter - {{showNumber ? &quot;shown&quot; : &quot;hidden&quot;}}&lt;/h2&gt;<br>  &lt;p *ngIf = &#39;showNumber&#39;&gt;{{num}}&lt;/p&gt;`,<br>  styles: [&#39;:host { text-align: center; }&#39;]<br>})<br>export class CounterComponent {<br><br>  num: number = 0;<br>  showNumber: boolean = true;<br><br>  constructor() { }<br><br>  increment() { this.num++; }<br>  show() { this.showNumber = true; }<br>  hide() { this.showNumber = false; } <br>  private toggle() { this.showNumber = !this.showNumber; }<br><br>}</pre><p>Now let’s take a look at our app.component.ts. I also used inline styles and template here since there isn&#39;t much code.</p><pre>import { Component } from &#39;@angular/core&#39;;<br><br>@Component({<br>  selector: &#39;app-root&#39;,<br>  template: `<br>    &lt;h1&gt;Angular-Material-Tutorial&lt;/h1&gt;<br><br>    &lt;app-counter #counter&gt;&lt;/app-counter&gt;<br>    &lt;button (click) = &#39;counter.increment()&#39;&gt;Add number&lt;/button&gt;<br>    &lt;button (click) = &#39;counter.show()&#39;&gt;Show Counter&lt;/button&gt;<br>    &lt;button (click) = &#39;counter.hide()&#39;&gt;Hide Counter&lt;/button&gt;<br>  `,<br>  styles: [<br>    `h1 {<br>      text-align: center;<br>      padding: 20px;<br>    }`,<br>    `button {<br>      border: 0;<br>      outline: 0;<br>      padding: 10px;<br>      border-radius: 8px;<br>      display: block;<br>      margin: 10px auto;<br>  }`]<br>})<br>export class AppComponent {}</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/250/0*v7whZhmOK-hjpOm0.png" /></figure><p>Notice how our app component has absolutely no code inside the class. Not even a constructor! Yet, if we click on the Add Number button, it will increment the count, and our Show and Hide Counter buttons will also work as expected.</p><p><strong>We managed to access the properties and methods of the </strong><strong>CounterComponent through the </strong><strong>AppComponent because of Template Referencing</strong>.</p><p>When we say &lt;app-counter #counter&gt;&lt;/app-counter&gt;, we are accessing this particular instance of the CounterComponent class. And since the properties and methods boil down to plain JavaScript Objects, we can access them as we do with regular objects ( counter.increment() for example). Any property or instance marked as private cannot be accessed through Template Referencing.</p><p>This simple, but powerful, feature of Angular allows us to accomplish useful tasks without needed to bloat our TypeScript Class. Additionally, this is the very technique that we will use to access many of the properties of the Angular Material Components in order to take full advantage of them.</p><h3>Conclusion</h3><p>In this article, we gained an understanding of what Angular Material is, added Angular Material to our project and learned about Template Referencing and how it relates to Angular Material.</p><p>In the next article, we’ll get started on simple components from the <a href="https://material.angular.io/components/categories/buttons">Buttons and Indicators Section</a>. Thanks a lot for reading! 😄</p><p><em>Originally published at </em><a href="https://dev.to/qarunqb/angular-material-handbook-setup-and-basics-3ie0"><em>https://dev.to</em></a><em> on May 30, 2020.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=63edec96032c" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[My Back-end Adventures — Setting up a local database (Postgres)]]></title>
            <link>https://qarunqb.medium.com/my-back-end-adventures-setting-up-a-local-database-postgres-8fe614511eb4?source=rss-f58cdda6891a------2</link>
            <guid isPermaLink="false">https://medium.com/p/8fe614511eb4</guid>
            <category><![CDATA[postgres]]></category>
            <category><![CDATA[expressjs]]></category>
            <category><![CDATA[docker]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Qarun Qadir Bissoondial]]></dc:creator>
            <pubDate>Sun, 10 May 2020 22:11:08 GMT</pubDate>
            <atom:updated>2020-11-07T08:54:07.093Z</atom:updated>
            <content:encoded><![CDATA[<h3>My Back-end Adventures — Setting up a local database (Postgres)</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*xwt-OV3B90TVgasd.png" /></figure><p>One of the things I really wanted to get started with was setting up a local database for my Express servers. While using an in-memory data object inside of Express is fine, I wanted something a little closer to a real project.</p><p>So I decided to have a local instance of Postgres running. What better way than to host your database inside of a docker container? It eliminates all the complexity of installing Postgres on your system itself and it’s easy to get up and running.</p><p>In this article, I’ll run through how to set up a local postgres database inside a docker container and connect your Express back end to it using Sequelize. Let’s go!</p><p><strong>TL;DR: All the code can be found </strong><a href="https://github.com/Qarun-Qadir-Bissoondial/express-postgres-docker"><strong>here</strong></a><strong>.</strong></p><h3>Setting up Docker</h3><p>First thing you’ll wanna do is to <a href="https://docs.docker.com/get-docker/">install docker</a> on your system as well as <a href="https://docs.docker.com/compose/install/">docker-compose</a>. Docker is a runtime that allows us to run software inside of containers regardless of operating system. That means no frustrating installs and no OS-specific instructions. It works for all! 😄</p><p>Once Docker and docker-compose is on your system and ready to go, you’ll need to create a docker-compose.yml file. This is a config file for docker-compose that can spin up multiple containers and lets them communicate. Copy and paste the following code into the docker-compose.yml:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e2b9b6d2057eef587d473bad3d6ec59d/href">https://medium.com/media/e2b9b6d2057eef587d473bad3d6ec59d/href</a></iframe><p>The config file does a couple things for us:</p><ul><li>Creates 2 services (containers) for us called postgres and pgadmin</li><li>Sets the default username and password for us to access externally</li><li>Maps the corresponding ports. 5432:5432 on the postgres container means that port 5432 on the host machine is mapped to 5432 inside the docker container. The same logic applies for 5050:80 for pgadmin</li><li>Creates volumes for our containers. Even if our container is shut down, our data will persist. postgres:/data/postgres means the postgres folder in our local machine is mapped to the /data/postgres folder inside the docker container</li><li>Creates a common network called postgres so that our 2 containers can communicate with each other.</li></ul><h3>Running the Docker containers and connecting PgAdmin to Postgres</h3><p>Run docker-compose up in your terminal. Your computer will download the specified versions of the containers before activating them.</p><p>Your console output should look something like the following. I’m running an ubuntu system but it should pretty much be the same thing.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/9dedfa132fb42997c16a3d61a3305b24/href">https://medium.com/media/9dedfa132fb42997c16a3d61a3305b24/href</a></iframe><p>Once this is up and running, go to localhost:5050 in your browser and you should be greeting with the PgAdmin login screen. This is the administrative interface for Postgres. While this is not necessary to have, it&#39;s still pretty cool.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/880/0*eCJocFwg4pr5Vhsl.png" /></figure><p>Log using the PGADMIN_DEFAULT_EMAIL and the PGADMIN_DEFAULT_PASSWORD from the docker-compose.yml file. In my example, these are pgadmin4@pgadmin.com and admin respectively.</p><p>Let’s just recap what we did so far. We created 2 docker containers, one for Postgres and one for PgAdmin. We then launched those 2 containers and connected to PgAdmin through localhost:5050 in the browser. Now we&#39;re going to connect PgAdmin to the Postgres container.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/880/0*0sYuCf63-cv_862k.png" /></figure><p>Create a new server by navigating to the right and right-clicking Servers &gt; Create &gt; Server.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/538/0*58MhJXUyrURnmFra.png" /></figure><p>Give your server a name. I’ll call mine express-postgres-docker. Then, navigate to the Connection tab. Fill out the details so it looks like the following:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/563/0*SdnOADhZ6UfgwZ1Y.png" /></figure><p>Let’s run through what’s happening:</p><ul><li>Host name/address is postgres. This field is asking us for the name or IP address of the machine that the Postgres database is located. Since we&#39;re using Docker, the container is considered a machine of its own with a name and address. The name is postgres as specified by our docker-compose.yml file. If we were connecting to a locally installed version of Postgres without Docker, it would have been localhost since the database would be located on your local machine.</li><li>Port is 5432. This is the standard Postgres port. Since both Docker container are using the same network, they can see each other&#39;s port without having to use different IP addresses</li><li>Maintenance Database is postgres. This is standard and should not be altered.</li><li>Username is postgres. This was specified as POSTGRES_USER in the docker-compose.yml file. If you changed it, then you need to specify that change in this field.</li><li>Password is password. This was specified as POSTGRES_PASSWORD in the docker-compose.yml file. If you changed it, then you need to specify that change in this field.</li></ul><p>Once you hit save, PgAdmin should be connected to your Postgres container.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/880/0*ieSfl4ZZ1HUnORp0.png" /></figure><h3>Setting up your Express server</h3><p>We’ll need to install a few packages to get started. Our dependencies are going to be:</p><ul><li>express</li><li>pg</li><li>pg-hstore</li><li>sequelize</li></ul><p>Once installed, you’ll need to create an app.js that looks like the following:</p><p>Run node app.js in your terminal and you should get the following output if your connection was successful:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/8654059599c427916ef3a6dd33b06e4b/href">https://medium.com/media/8654059599c427916ef3a6dd33b06e4b/href</a></iframe><pre>Listening on port 5000<br>Executing (default): SELECT 1+1 AS result<br>Database connected!</pre><h3>Conclusion</h3><p>Congratulations! You just set up Postgres and PgAdmin in Docker containers and connected it to an Express Sequelize Project. Now you can use this to actually store data for your projects or use it as a platform to start learning more about Database and Database Caching. Happy Coding! 😄</p><p><em>Originally published at </em><a href="https://dev.to/qarunqb/my-back-end-adventures-setting-up-a-local-database-postgres-508i"><em>https://dev.to</em></a><em> on May 10, 2020.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8fe614511eb4" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[My Back-end Adventures — Intro]]></title>
            <link>https://qarunqb.medium.com/my-back-end-adventures-intro-e472fda1ac70?source=rss-f58cdda6891a------2</link>
            <guid isPermaLink="false">https://medium.com/p/e472fda1ac70</guid>
            <category><![CDATA[coding]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Qarun Qadir Bissoondial]]></dc:creator>
            <pubDate>Sat, 09 May 2020 19:05:31 GMT</pubDate>
            <atom:updated>2020-11-07T08:39:27.889Z</atom:updated>
            <content:encoded><![CDATA[<h3>My Back-end Adventures — Intro</h3><p><strong>TL;DR</strong>: This series is about my journey into the world of Back-end Development. Every milestone, small accomplishment, frustration and major achievement is going to be documented in this series. I’ll include a few tutorial articles to run through set ups that I found challenging to understand so that others after me can have an easier time. Enjoy! 😄</p><p>Just until recently (at the time of publishing this article), I decided to dive into the world of Back end Web Development. I already had a lot of experience on the front end and a deep understanding of Angular. But I wanted to change my Web Development focus slightly as well as my career.</p><p>There were a lot of choices laid out in front of me such as:</p><ul><li>Python Flask</li><li>Node.js/Express</li><li>Golang</li><li>PHP</li><li>Elixir</li></ul><p>Eventually I settled on Node.js/Express since I was already familiar with JavaScript and already had done one or two really small Express projects on my own. Plus I really like JavaScript modern syntax.</p><p>The <a href="https://www.100daysofcode.com/">#100DaysOfCode</a> challenge seemed like a really good way to get me going. I’ve always had problems with motivation and keeping the discipline to stick with a habit so it was a good fit.</p><p>I laid out a bunch of topics to cover and projects along the way so that I don’t get stuck in tutorial hell. Here are some of those topics:Beginner</p><ul><li>Node.js Express basics</li><li>Routing</li><li>MiddleWare</li><li>View/Templating Engines</li><li>SQL ORM (Sequelize)</li><li>NoSQL ORM (Mongoose)</li><li>Security, Passwords and OAuth</li><li>Caching</li><li>State Management</li><li>More Database management</li><li>Node.js Core Modules</li><li>Web Sockets</li><li>NginX</li></ul><p>There are probably some more that I missed but I’ll get to them along the way. So far I’ve only covered some of the basics but I learned so much that I’m excited to keep going. Can’t wait to see what else I learn!</p><p><em>Originally published at </em><a href="https://dev.to/qarunqb/my-back-end-adventures-intro-3poo"><em>https://dev.to</em></a><em> on May 9, 2020.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e472fda1ac70" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[TDD in Angular — Understanding an Angular Unit Test]]></title>
            <link>https://qarunqb.medium.com/tdd-in-angular-understanding-an-angular-unit-test-fb6762a5f067?source=rss-f58cdda6891a------2</link>
            <guid isPermaLink="false">https://medium.com/p/fb6762a5f067</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[jasmine]]></category>
            <category><![CDATA[tdd]]></category>
            <category><![CDATA[angular]]></category>
            <dc:creator><![CDATA[Qarun Qadir Bissoondial]]></dc:creator>
            <pubDate>Tue, 21 Apr 2020 22:23:39 GMT</pubDate>
            <atom:updated>2020-05-11T10:42:15.053Z</atom:updated>
            <content:encoded><![CDATA[<h3>TDD in Angular — Understanding an Angular Unit Test</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*lVIJBj1KYuCnEG7P.png" /></figure><blockquote>Original article published <a href="https://dev.to/qarunqb/tdd-in-angular-understanding-an-angular-unit-test-jja">here</a>.</blockquote><p>In my <a href="https://dev.to/qarunqb/tdd-in-angular-the-basics-of-general-testing-2bfb">previous post</a>, I talked about the Basics of General Testing. It was a short introduction into the different types of testing and how to approach testing in Jasmine.</p><p>In this article, I want to take a look at the auto-generated unit test files of an Angular Application and explain what’s happening. I’ll unit test services for my examples since it’s a good place to start understanding the fundamentals. Also, Angular Components have a bit more going on under the hood and that requires an article of its own.</p><p>Many Angular developers get confused and even overwhelmed by what’s happening in a .spec.ts file. This article will change that.</p><p><em>Code for this article can be found </em><a href="https://github.com/Qarun-Qadir-Bissoondial/ng-jasmine-testing-demo/tree/understanding-an-angular-unit-test"><em>here</em></a><em>.</em></p><h3>Angular Services</h3><p>Services are by far the easiest to unit test. They’re simply Injectable classes that may or may not have some state and contain a collection of functions. However, they shouldn’t be taken lightly. <strong>Your services are where all your business logic should be.</strong> Therefore, testing them as much as you can will prove useful.</p><p>Let’s take a look at an InventoryService and its auto-generated .spec.ts file:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4c595b6da018a9534cedba3b75d093f3/href">https://medium.com/media/4c595b6da018a9534cedba3b75d093f3/href</a></iframe><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3fdfb3ade2c92eae290a2e71994a51dd/href">https://medium.com/media/3fdfb3ade2c92eae290a2e71994a51dd/href</a></iframe><p>There’s a few points to note here.</p><p>There’s a describe block that groups all our tests together for this service. A variable called service is also initialized.</p><p>The beforeEach block contains code that is run before every single unit test in this spec file. It helps us have a clean slate before running each test so that previous tests don&#39;t interfere. This helps with the essence of unit testing (testing one thing in isolation without any external factors).<br><em>There are other blocks of code like this to help us maintain clean tests, namely </em><em>beforeAll, </em><em>afterEach and </em><em>afterAll. You can read more about them and more pretty cool testing tools in the </em><a href="https://jasmine.github.io/api/3.3/global"><em>Jasmine Global API</em></a><em>.</em></p><p>Looking inside the beforeEach block, we see 2 unfamiliar pieces of code. TestBed.configureTestingModule creates a dummy module for us to work with. TestBed.inject initializes our service and injects it into that dummy module. This holds true for components, pipes, guards, etc. This is the unit testing philosophy combined with Angular&#39;s architecture.</p><p>An Angular application must have at least one module so a dummy module is created with only the piece of code being tested (in this case, the service) and nothing else. This way, nothing else from the outside can interfere with the tests. Pure Isolation.</p><p>Each it block of code is a unit test. it is a function that accepts 2 arguments: A string describing the test and a function that must contain an expect assertion function. This expect function is what Jasmine runs to assert expected values against actual results.</p><p>it(&#39;should be created&#39;), () =&gt; {...} is a unit test that is always created for any component, pipe, service, etc. It doesn&#39;t make sense looking at other unit tests if we can&#39;t initialize our code in the first place.</p><h3>Building our Service</h3><p>Let’s say that I wanted to add some code to track the number of items in my inventory and a way to increment and decrement the amount.</p><p><strong>Remember! We’re approaching this from a TDD standpoint. We can write empty placeholders and then Tests first!</strong></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3078e839cfe0ccd52c8ec246ad621dfd/href">https://medium.com/media/3078e839cfe0ccd52c8ec246ad621dfd/href</a></iframe><p>We write tests for what we want our code to do and then consider other cases. Tests for main functionality should look something like this:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/2ff1e600daf6c154d9f30091143da36b/href">https://medium.com/media/2ff1e600daf6c154d9f30091143da36b/href</a></iframe><p>You’ll notice I used fdescribe as opposed to describe. This means &quot;Focused Describe&quot; and Jasmine will only run this suite of tests instead of all tests in the Application.</p><p>When we run our unit tests, we’ll notice some failures (as expected).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/880/1*TCECy-ipMV9g1fAvteildA.png" /></figure><p>It’s telling us that the “should increment the count” and “should decrement the count” tests are failing. This is expected since we didn’t write any code in there as yet. Let’s change that.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/32aa30fbfc1efba3eb0b7a50c6bc9033/href">https://medium.com/media/32aa30fbfc1efba3eb0b7a50c6bc9033/href</a></iframe><p>And now our tests are passing:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/270/1*jPrAR2Go2goNpshEqj-ITg.png" /></figure><p>The more astute among you might have realized that our decrement function isn’t finished. We shouldn’t be able to decrement if the inventoryCount is already 0.</p><p>A reasonable test for this can be:</p><pre>it(&#39;should not decrement when count is 0&#39;, () =&gt; {<br>    expect(service.inventoryCount).toBe(0);<br>    service.decrementCount();<br>    expect(service.inventoryCount).toBe(0);<br>});</pre><p>Re-running the tests gives us:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/880/1*0HBDj-Sur43M7uu21VyKcQ.png" /></figure><p>Our function currently decrements whatever value is stored in the service. We want it to decrement only when the value isn’t 0. This is also a simple way to make sure that inventoryCount never falls below 0 (assuming you want your system like that).</p><p>We can modify the function to be:</p><pre>decrementCount() {<br>    <br>    if (this.inventoryCount === 0) return;<br>    this.inventoryCount--;</pre><pre>}</pre><p>Now our tests are passing again.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/305/1*6E-PlzOwsFfOdCOCA-FSnQ.png" /></figure><h3>Conclusion</h3><p>In this article, we covered the following:</p><ul><li>The basic structure of an Angular Unit Test</li><li>What happens in the beforeEach block</li><li>Why a dummy module is necessary for testing</li><li>Building an Angular Service using TDD</li></ul><p>There are a lot more of these articles to come where we’ll dive deeper into services, mocking, component life cycles, etc. Stay tuned for more and thanks a bunch for reading! 😄</p><p><em>Originally published at </em><a href="https://dev.to/qarunqb/tdd-in-angular-understanding-an-angular-unit-test-jja"><em>https://dev.to</em></a><em> on April 21, 2020.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=fb6762a5f067" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[TDD in Angular — The Basics of General Testing]]></title>
            <link>https://qarunqb.medium.com/tdd-in-angular-the-basics-of-general-testing-8513dc75900e?source=rss-f58cdda6891a------2</link>
            <guid isPermaLink="false">https://medium.com/p/8513dc75900e</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[tdd]]></category>
            <category><![CDATA[jasmine]]></category>
            <category><![CDATA[angular]]></category>
            <dc:creator><![CDATA[Qarun Qadir Bissoondial]]></dc:creator>
            <pubDate>Sun, 19 Apr 2020 00:32:02 GMT</pubDate>
            <atom:updated>2020-05-11T10:28:20.309Z</atom:updated>
            <content:encoded><![CDATA[<h3>TDD in Angular — The Basics of General Testing</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*xzUgYkpQEnMt42bB.png" /></figure><blockquote>Original article published <a href="https://dev.to/qarunqb/tdd-in-angular-the-basics-of-general-testing-2bfb">here</a></blockquote><p>You’ve all hear the crowd harping about how great testing is. But has anyone ever told you what testing is? Or what it means? Or how to even approach testing?</p><p>Don’t worry, young padawan. I’ll guide you through the basics of testing, the different types of testing and how to code in a Test-Driven Development style in Angular.</p><p><em>Hint: You can find all the completed code for this article </em><a href="https://stackblitz.com/edit/jasmine-testing-demo"><em>here</em></a><em>.</em></p><h3>Why bother to test?</h3><p>Consider this: If you’re a car manufacturer, are you going to sell cars when you don’t know whether or not it works? If you’re a good car dealer then of course you’ll make sure that it works in all the expected conditions. Why is software any different?</p><p><strong>Testing gives developers the confidence that our code will work 100% of the time as expected in the expected conditions.</strong> If not, then at least our code can <em>fail gracefully</em> (more on that later). <a href="https://www.youtube.com/watch?v=BSaAMQVq01E">Here’s a really nice (but slightly long) video on how TDD relates to good code and professionalism</a>.</p><h3>Types of Tests</h3><p><strong>Regression Testing</strong></p><p>You’ve actually unconsciously done this type of testing in all the code that you’ve written! Regression testing formally refers to checking if changes to one part of the code has affected any other parts.</p><p>We might unprofessionally know this as making a change, seeing something else break and following the breadcrumbs of broken code until everything works.</p><p><strong>Unit Testing</strong></p><p>This type of testing will make up at least 65% of your test suite. It’s focused on testing individual components. When I say “components” here, I don’t mean Angular or React components, I’m just referring to single, small, individual pieces of logic.</p><p>That doesn’t mean we’re going to test each and every function but we test those pieces of code that are most important (which are usually those focused around business logic).</p><p>So for example, in an Inventory Management System, we’ll want a test to ensure discounts are applied to certain items.</p><p><strong>Integration Testing</strong></p><p>We know our individual components work individually, but we also need to make sure they don’t break when we put them together. This is what Integration Tests are for.</p><p>In our Inventory Management System, we’ll want tests to make sure that a restocking order is places when inventory on a certain item falls below a certain amount. These tests may combine Inventory Counts and an Ordering System.</p><p><strong>End-to-End (e2e) Testing</strong></p><p>The applications we write usually have a start point (for example, a login) and an endpoint (for example, a purchase). Testing our apps from start to finish (or from <strong>end to end</strong>) is critical as this is as close to real-world usage as automated testing can get.</p><p>You’ll want to take more customer-driven scenarios into these tests such as navigation within the app to ensure the user is still authenticated or if animations and error messages pop up after certain actions.</p><p>There are probably more types of tests but these mentioned are the most common.</p><h3>How to prepare yourself for Test-Driven Development</h3><p>Test-Driven Development simply means to write our tests before we write our code. Since most of us haven’t grown up with TDD in mind, it sounds pretty absurd. Why write the tests first when there’s no code to start with?</p><p>The reason is that it keeps us very focused on what the code is supposed to do and nothing more. In a way, we subconsciously do this when we write our code, but we don’t put down our thoughts into tests.</p><p>We usually start off with what the code is supposed to do in our heads, write the code in our IDE and then assume it works. Writing out tests gets those initial thoughts out of our heads and into a form that’s more concrete.</p><p>Let’s do a simple example. We want to write a function that accepts an object, capitalizes the value in the “name” key and returns a new object.</p><p><strong>You can fork </strong><a href="https://stackblitz.com/edit/jasmine-testing"><strong>this StackBlitz repo</strong></a><strong> and code along.</strong></p><p>We’ll write an empty function first and then write our tests.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d5d83b32b2c4464de2c72afbd19d2aad/href">https://medium.com/media/d5d83b32b2c4464de2c72afbd19d2aad/href</a></iframe><p>We know what we want our code to do, so let’s write the corresponding test. If you’re using Jasmine, the first unit test should look something like this. Remember, we have an empty function so the first test should fail.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f81cb11edaeaab93c893a7100289e2fb/href">https://medium.com/media/f81cb11edaeaab93c893a7100289e2fb/href</a></iframe><p>And the resulting failing test:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/818/1*oc0bQpgFNiVapOhU4Ncclw.png" /></figure><p>We expect that the actualResult should be the same as the expectedResult. This is the basis of all tests. As long as our expectations match what is actually produced, then our tests will pass.</p><p>Now we can modify the code so that the test passes.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/964c87c322b590c3d807ba8898e173eb/href">https://medium.com/media/964c87c322b590c3d807ba8898e173eb/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/730/1*vYq9pZAMZyXUvufHffoV1g.png" /></figure><p>We’ve just done TDD! We thought about what the code needed to do, wrote the test first and then wrote the code to make the test pass.</p><h3>Handling more test cases</h3><p>Our code above works fine but it assumes that the object:</p><ul><li>is defined</li><li>has a key called “name”</li><li>has a defined value in the key called “name”</li><li>has a string value in the key called “name”</li></ul><p>When writing functions, you may not know where your arguments may come from (perhaps from sources that you cannot easily control such as form data or from an HTTP request). You have to be prepared for a number of cases like those described above so that it is robust. <strong>The more assumptions you make, the more room for error that you leave in your code.</strong></p><p>Let’s throw in some more test cases and see what happens:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/276657831d7fbbba2b109ebef97c5ffe/href">https://medium.com/media/276657831d7fbbba2b109ebef97c5ffe/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/880/1*l3ghhugl8VONMLNpeTf8sA.png" /></figure><p>Our tests are failing again so we know the areas that we need to work on.<br> I’ve decided to include a name key with an empty string if the name isn’t available. I’ve also decided to throw an error if the name key in the object is not a string or if the object is falsy. Let’s modify the code so that it works in those cases.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/fe417f5e99efbd04a319cfe8165ef807/href">https://medium.com/media/fe417f5e99efbd04a319cfe8165ef807/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/456/1*_S8p7q54zOBkSrsBkxZcvA.png" /></figure><p>And now all our tests are passing:</p><h3>Final Words</h3><p>Test-Driven Development allows us to write simple, yet robust code. It teaches us to consider many cases upfront as opposed to just the way the code is supposed to work. This way, the code isn’t prone to breaking at all, or at least as often.</p><p>Tests also act as a good form of documentation. Running the tests on a codebase and seeing all the test cases gives us a pretty good indication of what the code is supposed to do.</p><p>Unit test descriptions tell us what each piece of logic is supposed to do. Integration tests tell us how pieces are supposed to connect together. End-to-end tests tell us what to expect when using the entire system.</p><p><em>Originally published at </em><a href="https://dev.to/qarunqb/tdd-in-angular-the-basics-of-general-testing-2bfb"><em>https://dev.to</em></a><em> on April 19, 2020.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8513dc75900e" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Use Pipes in your next Angular Application! (Part 4)]]></title>
            <link>https://qarunqb.medium.com/use-pipes-in-your-next-angular-application-part-4-8c06a25647ef?source=rss-f58cdda6891a------2</link>
            <guid isPermaLink="false">https://medium.com/p/8c06a25647ef</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[angular]]></category>
            <dc:creator><![CDATA[Qarun Qadir Bissoondial]]></dc:creator>
            <pubDate>Thu, 09 Apr 2020 14:03:50 GMT</pubDate>
            <atom:updated>2020-04-09T14:16:32.242Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*xeXFUBZWFQqn5kms" /><figcaption>Photo by <a href="https://unsplash.com/@dvnil?utm_source=medium&amp;utm_medium=referral">Danil Sorokin</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><blockquote>Article originally published <a href="https://dev.to/qarunqb/use-pipes-in-your-next-angular-application-part-4-50aj">here</a></blockquote><p>Pipes are a really simple way to transform how data is displayed to the user. Angular comes with lots of built-in pipes for common scenarios (JsonPipe, CurrencyPipe, DatePipe, etc). But what if you need something custom for your project?</p><p>In this article, we’ll be exploring how to create your own pipes. I’ll run through a simple example that adds the correct order suffix to a number (eg. 1st, 12th, -123rd, etc). Let’s dive in!</p><p>(<a href="https://stackblitz.com/edit/ng-pipes-demo">All code here</a>)</p><h3>Creating your own Pipes</h3><p>The first thing you’ll need to do is to come up with a suitable name for your pipe. It should reflect what the pipe does. In my case, I’ll call the pipe OrderSuffix. Then, run the following command in your terminal.</p><p>ng generate pipe OrderSuffix</p><p>This will add your pipe to your declarations array in AppModule. The generated code should look like this:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/93167f4d0d835e24a676efe95c957193/href">https://medium.com/media/93167f4d0d835e24a676efe95c957193/href</a></iframe><p>The transform function is responsible for taking the input from the HTML template and producing the output to be displayed.</p><p>We want to be able to add an order suffix based on the number, which is mostly determined by the last digit (least significant digit). So 1 becomes 1st, 2 becomes 2nd, 4 becomes 4th and so forth. It’s also helpful to note that we’re taking in a number and returning a string.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/9c9e2e1723d9a755f66772818ac6f73f/href">https://medium.com/media/9c9e2e1723d9a755f66772818ac6f73f/href</a></iframe><p>This pipe looks pretty good so far. We defined a suffix map for digits ending in 1, 2 and 3, converting them to 1st, 2nd and 3rd respectively. If the last digit is none of these 3, then we assume the suffix is “th” (4th, for example).</p><p>We can demo our pipe inside a simple component as follows:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/65d7545496760e8576443a851025b50a/href">https://medium.com/media/65d7545496760e8576443a851025b50a/href</a></iframe><p>The component displays the array of numbers with their order suffixes. However, if we look at the very last number, there’s a problem.</p><pre>1st<br>2nd<br>3rd<br>14th<br>-128th<br>11st</pre><p>We need to convert 11 to 11th, not to 11st. Our current pipe will also convert 12 to 12nd and 13 to 13rd, which aren’t correct. Remember that the pipe has to work with larger numbers as well, so for example, 1259239411 should still give 1259239411th.</p><p>Notice how this problem only occurs for 11, 12 and 13 or numbers that end with 11, 12 and 13. We should deal with those cases first before our general code runs.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3c1bc7fe600568c2ba00c096e7392013/href">https://medium.com/media/3c1bc7fe600568c2ba00c096e7392013/href</a></iframe><p>Now, our pipe looks for the last 2 digits being 11, 12 or 13 and returns the number with the suffix “th” for all of them. If not, then we run our previous code. Now our output looks a little more accurate.</p><pre>1st<br>2nd<br>3rd<br>14th<br>-128th<br>11th</pre><h3>Lessen your burden:</h3><p>If you’re writing a custom parsing function just to change how data is displayed, then you’re better off putting that parsing function inside a pipe.</p><p>Without using pipes, inside your component would follow this process:</p><ul><li>Define/Import your parsing function</li><li>Get the data you want to transform</li><li>Run the data through the function and store the result in a new variable</li><li>Display that new variable</li></ul><p>Whereas with Pipes, we just:</p><ul><li>Define the parsing function inside the pipe</li><li>Use the pipe in the component HTML template.</li></ul><p>No extra imports, no extra variables, and the component is <a href="https://dev.to/mquanit/concept-of-smart-dumb-components-in-angular-2fom">as dumb as possible</a>.</p><h3>Conclusion</h3><p>Now you know how to create your own pipes!</p><p>This is also the end to my 4 part series on Pipes in Angular. There are 2 built-in pipes that I haven’t mentioned ( <a href="https://angular.io/api/common/I18nPluralPipe">I18nPluralPipe</a> and <a href="https://angular.io/api/common/I18nSelectPipe">I18nSelectPipe</a>). Now you know enough to explore these pipes on your own and create some of your own!</p><p>Good luck in your Angular journey! 😄</p><p><em>Originally published at </em><a href="https://dev.to/qarunqb/use-pipes-in-your-next-angular-application-part-4-50aj"><em>https://dev.to</em></a><em> on April 9, 2020.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8c06a25647ef" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Use Pipes in your next Angular Application! (Part 3)]]></title>
            <link>https://qarunqb.medium.com/use-pipes-in-your-next-angular-application-part-3-f46cfea1c10b?source=rss-f58cdda6891a------2</link>
            <guid isPermaLink="false">https://medium.com/p/f46cfea1c10b</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[angular]]></category>
            <dc:creator><![CDATA[Qarun Qadir Bissoondial]]></dc:creator>
            <pubDate>Fri, 03 Apr 2020 13:33:38 GMT</pubDate>
            <atom:updated>2020-04-03T13:51:23.754Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*pkX-xoemeOIFJFhC" /><figcaption>Photo by <a href="https://unsplash.com/@quinten149?utm_source=medium&amp;utm_medium=referral">Quinten de Graaf</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><blockquote>Original article published <a href="https://dev.to/qarunqb/use-pipes-in-your-next-angular-application-part-3-30nd">here</a></blockquote><p>The main use of Pipes in Angular is to transform how data is displayed. Dates, currency and JSON objects are just some of the structures that Angular Pipes can work with.</p><p>Check out my <a href="https://dev.to/qarunqb/use-pipes-in-your-next-angular-application-part-1-39mk">first</a> and <a href="https://dev.to/qarunqb/use-pipes-in-your-next-angular-application-part-2-3nnm">second</a> articles on Pipes where we cover some of the simpler pipes.</p><p>In this article, we’ll be moving on to 2 very useful pipes:</p><ul><li><a href="https://angular.io/api/common/DatePipe">DatePipe</a></li><li><a href="https://angular.io/api/common/AsyncPipe">AsyncPipe</a></li></ul><h4>DatePipe</h4><p>This is used for displaying JavaScript Date Objects in a readable format. Angular provides many ways for us to configure the DatePipe, from full or abbreviated day names, from the hours down to the seconds and, of course, varying locales as well (en-US locale is used by default).</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/6ac099204fae5c1e2e0a67793f979b75/href">https://medium.com/media/6ac099204fae5c1e2e0a67793f979b75/href</a></iframe><p>And the corresponding output:</p><pre>Date without Pipe: Fri Apr 03 2020 08:43:22 GMT-0400 (Venezuela Time)<br>Date with Pipe: Apr 3, 2020</pre><pre>Showing Dates:<br>Short Date: 4/3/20<br>Medium Date: Apr 3, 2020<br>Long Date: April 3, 2020</pre><pre>Date Formatting with Parameters:<br>dd/mm/yyyy: 3 Apr 2020<br>yyyy/mm/dd: 2020 Apr 3</pre><pre>Formatting Times<br>Short time: 8:43 AM<br>Medium time: 8:43:22 AM<br>Long time: 8:43:22 AM GMT-4</pre><p>There’s loads more examples on the <a href="https://angular.io/api/common/DatePipe">DatePipe Documentation</a>. Pre-defined formatting options as well as custom formats.</p><h4>AsyncPipe</h4><p>Asynchronous Programming is at the very heart of JavaScript. With Angular being built on RxJS and using Observables for HTTP requests, more and more developers end up writing the same code just to extract their data from HTTP Async responses.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/20bc0f811e4a1f0f172fa08c8cd2ba56/href">https://medium.com/media/20bc0f811e4a1f0f172fa08c8cd2ba56/href</a></iframe><p>With the AsyncPipe, it can dramatically reduce the above code to the following:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ade6efd6d889c25ee18779fadaa9e187/href">https://medium.com/media/ade6efd6d889c25ee18779fadaa9e187/href</a></iframe><p>The HTML from the second example is important.</p><p>Line 8 says: <em>“Subscribe to the </em><em>character observable and store the response data in </em><em>char. If </em><em>char is defined, then show the </em><em>&lt;p&gt; tag. Else, show the </em><em>#loading template.&quot;</em></p><p>This allows us to set a variable to store the response data straight from the HTML as opposed to declaring it in our Component TypeScript.</p><p>Additionally, notice how in the second example, we didn’t need to call subscribe. This is because <em>AsyncPipe automatically subscribes for you</em>. Generally speaking, we don’t need to unsubscribe from HTTP Observables since <a href="https://medium.com/@garfunkel61/unsubscribing-from-angular-httpclient-data-requests-observables-44fc5a4965d5">Angular auto-unsubscribes for us</a>.</p><p>But in general, <em>AsyncPipe automatically unsubscribes Observables on Component Destruction</em>. That’s a lot less for us for think about and a lot less for us to code. <strong>Always leverage the framework as much as possible.</strong></p><p>Note that the same works for promises as well :)</p><h3>Conclusion</h3><p>This article was a short, but powerful, introduction to using DatePipe and AsyncPipe in Angular. DatePipe is used to display dates and can show various formats. AsyncPipe extracts the value from an asynchronous data structure and gives us access to it straight from the HTML.</p><p>Thanks a bunch for reading! Stay tuned for the next Article where I talk about making your own pipes 😄</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/480/0*gsmVd4pPmFibMGfj.gif" /></figure><p><strong>Sore eyes?</strong></p><p><a href="https://dev.to/enter"><strong>dev.to</strong></a> now has dark mode.</p><p>Select <strong>night theme</strong> in the “misc” section of <a href="https://dev.to/enter"><strong>your settings</strong></a> ❤️</p><p><em>Originally published at </em><a href="https://dev.to/qarunqb/use-pipes-in-your-next-angular-application-part-3-30nd"><em>https://dev.to</em></a><em> on April 3, 2020.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f46cfea1c10b" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Use Pipes in your next Angular Application! (Part 2)]]></title>
            <link>https://qarunqb.medium.com/use-pipes-in-your-next-angular-application-part-2-f3b9a4b5e416?source=rss-f58cdda6891a------2</link>
            <guid isPermaLink="false">https://medium.com/p/f3b9a4b5e416</guid>
            <category><![CDATA[angular]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[angular-4]]></category>
            <category><![CDATA[angular2]]></category>
            <dc:creator><![CDATA[Qarun Qadir Bissoondial]]></dc:creator>
            <pubDate>Wed, 01 Apr 2020 03:20:50 GMT</pubDate>
            <atom:updated>2020-04-01T03:35:22.088Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*pZRAqHZNc0z9BTQF" /><figcaption>Photo by <a href="https://unsplash.com/@victor_g?utm_source=medium&amp;utm_medium=referral">Victor Garcia</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><blockquote><a href="https://dev.to/qarunqb/use-pipes-in-your-next-angular-application-part-2-3nnm">Article originally published to dev.to</a></blockquote><p>Pipes are a pretty useful feature of Angular that allow us to transform the way we display data to our user without actually altering the data. Many times we may want to display dates, money, currency or just numbers in a preferred format.</p><p>This article is a continuation of <a href="https://dev.to/qarunqb/use-pipes-in-your-next-angular-application-part-1-39mk">my first post about pipes here</a> where we got familiar with the simpler pipes:</p><h4>Case-based pipes</h4><ul><li>UpperCasePipe</li><li>LoweCasePipe</li><li>TitleCasePipe</li></ul><h4>Number-based pipes</h4><ul><li>DecimalPipe</li><li>PercentPipe</li><li>CurrencyPipe</li></ul><p>We’ll be looking at 3 more pipes in this article, namely:</p><ul><li><a href="https://angular.io/api/common/JsonPipe">JsonPipe</a></li><li><a href="https://angular.io/api/common/SlicePipe">SlicePipe</a></li><li><a href="https://angular.io/api/common/KeyValuePipe">KeyValuePipe</a></li></ul><p><em>TL;DR: </em><a href="https://stackblitz.com/edit/ng-pipes-demo"><em>Here’s the sample project with all the code</em></a></p><h3><a href="https://angular.io/api/common/JsonPipe">JsonPipe</a></h3><p>This pipe gives us a simple way to display complex data straight to our template. While we’re not accustomed to showing raw JSON data for our users to see, Angular mentions in their documentation that this pipe is useful for debugging. I’ve personally found it immensely useful for displaying the value of a Reactive Form while changing the values.</p><p>Let’s look at a general example:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b8564a58c2462c9fb662f9c3db734bcb/href">https://medium.com/media/b8564a58c2462c9fb662f9c3db734bcb/href</a></iframe><p>And the corresponding output:</p><pre>Object: [object Object]<br>Object with JsonPipe: { &quot;name&quot;: &quot;Qarun&quot;, &quot;age&quot;: 25, &quot;food&quot;: &quot;Cheesecake&quot;, &quot;languages&quot;: [ { &quot;name&quot;: &quot;JavaScript&quot;, &quot;proficiency&quot;: &quot;Wizard&quot; }, { &quot;name&quot;: &quot;Python&quot;, &quot;proficiency&quot;: &quot;Avergae&quot; }, { &quot;name&quot;: &quot;Elixir&quot;, &quot;proficiency&quot;: &quot;Beginner&quot; } ] }</pre><pre>array: 1,2,3,4,5,6<br>array: [ 1, 2, 3, 4, 5, 6 ]</pre><p>Displaying the object from the component directly into the HTML causes the raw string version to be shown. This is achieved by JavaScript automatically running data.toString(), hence the [object Object] in the examples without the pipe.</p><p>However, with the JsonPipe, it runs the variable through JSON.stringify, which is why our object shows properly and why the array with the pipe has brackets.</p><h3><a href="https://angular.io/api/common/SlicePipe">SlicePipe</a></h3><p>You’re probably familiar with the <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/slice">Array slice</a> and the <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/slice">String slice</a> methods in Vanilla JavaScript. They both slice out and return a specified portion of the Array/String.</p><p>Angular offers us a SlicePipe which works the same way, allowing us to manipulate with strings and arrays directly in our HTML template. It even allows us to change an array that *ngFor is applied to.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d43cac38e4e0cd5067fe80ed733110be/href">https://medium.com/media/d43cac38e4e0cd5067fe80ed733110be/href</a></iframe><p>The above example shows one of the many use cases for the SlicePipe: hiding a long string. A button or “Read more” text can be clicked to show the full string. It’s also useful if you want to build your own pagination when applied to *ngFor.<br><em>Notice how in the very last array example, we included the JsonPipe at the end. </em><strong><em>Pipes can be chained together</em></strong>.</p><h3><a href="https://angular.io/api/common/KeyValuePipe">KeyValuePipe</a></h3><p>Another useful Pipe is the KeyValuePipe which allows is to display objects. This is similar to the JsonPipe but with a slight twist. <em>It automatically sorts the object by keys.</em></p><p>Usually, the process of displaying an object’s sorted contents goes something like this:</p><ul><li>Get the object from some source in your TypeScript</li><li>Use Object.keys, Object.values, or Object.entries</li><li>Sort resulting array into a new array</li><li>Loop through new, sorted array and display values</li></ul><p>KeyValuePipe cuts down that process by 50%. All you need is your comparator function and Angular does the rest. By allowing us to supply the comparator function, we still have the power to sort complex data structures. If no function is provided, then <a href="https://github.com/angular/angular/blob/master/packages/common/src/pipes/keyvalue_pipe.ts">defaultComparator</a> is used.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/722f461537cbfb4a00611e5ee516af10/href">https://medium.com/media/722f461537cbfb4a00611e5ee516af10/href</a></iframe><p>And the corresponding output:</p><pre>Key-Value Pipes!</pre><pre>Default Key-Value pipe<br>age - 25<br>food - Cheesecake<br>name - Qarun </pre><pre>Custom Sort functions: </pre><pre>Sort by decreasing length of string values<br>food - Cheesecake<br>name - Qarun<br>age - 25 </pre><pre>Sort by increasing expiry dates<br>Cabbage expires at Apr 14, 2020<br>Tomatoes expires at Apr 17, 2020<br>Lettuce expires at Apr 21, 2020</pre><p>In the code above, I displayed 3 examples:</p><ul><li>Default KeyValuePipe</li><li>Sorting by decreasing length of strings</li><li>Sorting by increasing Expiry Date</li></ul><p>The power of this pipe is only limited by your comparator function. Also, If you’re wondering how my dates are displayed in such a readable format, that’s because of the <a href="https://angular.io/api/common/DatePipe">DatePipe</a> which I’ll be covering as part of my next Article :)</p><h3>Conclusion</h3><p>You’ve made it to the end! In this article, we covered:</p><ul><li>JsonPipe</li><li>SlicePipe</li><li>KeyValuePipe</li></ul><p>Thanks a lot for reading! Look out for my next article on some more exciting pipes :D</p><p><em>Originally published at </em><a href="https://dev.to/qarunqb/use-pipes-in-your-next-angular-application-part-2-3nnm"><em>https://dev.to</em></a><em> on April 1, 2020.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f3b9a4b5e416" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Use Pipes in your next Angular Application! (Part 1)]]></title>
            <link>https://qarunqb.medium.com/use-pipes-in-your-next-angular-application-part-1-92fa8b0aa104?source=rss-f58cdda6891a------2</link>
            <guid isPermaLink="false">https://medium.com/p/92fa8b0aa104</guid>
            <category><![CDATA[pipes]]></category>
            <category><![CDATA[angular]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Qarun Qadir Bissoondial]]></dc:creator>
            <pubDate>Sat, 28 Mar 2020 23:57:44 GMT</pubDate>
            <atom:updated>2020-03-30T00:28:34.285Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*53LIDvQROJiu1YBM" /><figcaption>Photo by <a href="https://unsplash.com/@samthewam24?utm_source=medium&amp;utm_medium=referral">Samuel Sianipar</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><blockquote>Article originally published to <a href="https://dev.to/qarunqb/use-pipes-in-your-next-angular-application-part-1-39mk">dev.to</a></blockquote><p>Let’s say that you’re looking for a way to transform the way data is displayed without actually changing the data. But you’re tired of writing the same parsing functions over and over again. Don’t worry, Angular Pipes have got you covered! They provide a clean, lightweight method to transform your data straight from the HTML template. No longer will you need to worry about how to display JSON or dates, or even Title Casing strings.</p><p>This series of articles will try to encourage you to use Pipes in your daily workflow. I’ll be demonstrating how to use the <a href="https://angular.io/api?type=pipe">Pipes that come with Angular</a>. Later in the series, I’ll show how to create your own pipes. Let’s get started!</p><p><em>TL;DR: To see the full project, check it out </em><a href="https://stackblitz.com/edit/ng-pipes-demo"><em>here</em></a><em>.</em></p><h3>Case Pipes</h3><p>These pipes simply change the case of the text being displayed. There are 3 main pipes:</p><ul><li><a href="https://angular.io/api/common/UpperCasePipe">UpperCasePipe</a></li><li><a href="https://angular.io/api/common/LowerCasePipe">LowerCasePipe</a></li><li><a href="https://angular.io/api/common/TitleCasePipe">TitleCasePipe</a></li></ul><p>The code snippets below demonstrate these 3 pipes in action:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/26f1ac8ac8fb2fad3a5b825b2eb7654a/href">https://medium.com/media/26f1ac8ac8fb2fad3a5b825b2eb7654a/href</a></iframe><p>And this is the output:</p><pre>Text-based Pipes!<br>This is our string: My sTriNg to ChANge!<br>Uppercase Pipe -&gt; MY STRING TO CHANGE!<br>Lowercase Pipe -&gt; my string to change!<br>Titlecase Pipe -&gt; My String To Change!</pre><p>Displaying different cases has never been easier ;)</p><h3>Number Pipes (and also, Pipes with Parameters?!)</h3><p>Let’s say you want to calculate a decimal number as accurately as possible but you don’t want to display a bajillion decimal places. Number Pipes can help us out here. There are 3 main types:</p><p>Each of these may warrant their own explanation.</p><h4>DecimalPipe</h4><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/32890d5139a8d7bd139301971b87042f/href">https://medium.com/media/32890d5139a8d7bd139301971b87042f/href</a></iframe><p>This allows us to control the number of decimal places of a small number. See the following code:</p><ul><li><a href="https://angular.io/api/common/DecimalPipe">DecimalPipe</a></li><li><a href="https://angular.io/api/common/PercentPipe">PercentPipe</a></li><li><a href="https://angular.io/api/common/CurrencyPipe">CurrencyPipe</a></li></ul><p>And this is the output:</p><pre>Number-based Pipes!<br>This is our small number: 0.14285714285714285<br>Decimal Pipe: 0.143 (This is 3 decimal places by default)<br>Decimal Pipe at 4 decimal places: 0.1429</pre><p>You’ll notice something slightly different about this pipe. It doesn’t just say {{smallNumber | number}}. It says {{smallNumber | number:&#39;1.4&#39;}}. What&#39;s going on?</p><p>Some Angular Pipes are built to accept <em>parameters</em>. At the end of the day, the Pipe is simply a function. However, parameters for Pipes are always strings. In this particular example, ‘1.4’ is broken up to mean “One digit before the decimal point and a minimum of 4 digits after the decimal point”. You can find more information on the DecimalPipe <a href="https://angular.io/api/common/DecimalPipe">here</a>.</p><p>When building your own pipes, it’s up to you to decide the format for the parameter and what it means.</p><h4>PercentPipe</h4><p>This simply converts our decimal number to display a percentage.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4bc39859452c85bf540f6379a441d05f/href">https://medium.com/media/4bc39859452c85bf540f6379a441d05f/href</a></iframe><p>And the corresponding output:</p><pre>Our number for percent: 0.12<br>Percent Pipe: 12%</pre><h4>CurrencyPipe</h4><p>Angular also provides the CurrencyPipe for displaying different currencies as follows:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b349a0e6f8389871d67a7a04c2a16799/href">https://medium.com/media/b349a0e6f8389871d67a7a04c2a16799/href</a></iframe><p>And the output:</p><pre>Currency Pipes!<br>Our number: 19.99<br>Currency Pipe: $19.99<br>Canadian Currency: CA$19.99<br>Indian Currency: ₹19.99</pre><p>This pipe takes in multiple parameters but the main one to focus on is the type of currency to be displayed. In the above example, I displayed Canadian (CAD) and Indian (INR) currencies.</p><h4>A word about locale.</h4><p>We may be accustomed to writing large numbers as 1,000,000.25. But that might not be common for other countries. For example, some countries would write the same number as 1.000.000,25. Other countries may separate every three digits with spaces, or separate every 4 digits instead of 3.</p><p>The CurrencyPipe also helps us handle this but you’ll need to import the locale data at the module level and build with specific parameters using the CLI. This applies for any locale usage in Angular. See <a href="https://github.com/angular/angular/issues/20286#issuecomment-343649893">here</a> for more info.</p><h3>Conclusion</h3><p>And that’s it! That’s your introduction to using Pipes in Angular. They’re pretty simple to use in your application without having to write functions to do the parsing for us.</p><p>Stay tuned for Part 2 of this series where we dive into more complicated pipes :D</p><p><em>Originally published at </em><a href="https://dev.to/qarunqb/use-pipes-in-your-next-angular-application-part-1-39mk"><em>https://dev.to</em></a><em> on March 28, 2020.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=92fa8b0aa104" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>