<?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: Nichola Alkhouri</title>
    <description>The latest articles on DEV Community by Nichola Alkhouri (@nicholaalkhouri).</description>
    <link>https://dev.to/nicholaalkhouri</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%2F575222%2Fff8e9777-6380-4402-80a6-ff66d65d04df.jpeg</url>
      <title>DEV Community: Nichola Alkhouri</title>
      <link>https://dev.to/nicholaalkhouri</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/nicholaalkhouri"/>
    <language>en</language>
    <item>
      <title>Generic Approach to Consume REST API in Angular</title>
      <dc:creator>Nichola Alkhouri</dc:creator>
      <pubDate>Tue, 16 Mar 2021 18:51:32 +0000</pubDate>
      <link>https://dev.to/playfulprogramming-angular/generic-approach-to-consume-rest-api-in-angular-4poj</link>
      <guid>https://dev.to/playfulprogramming-angular/generic-approach-to-consume-rest-api-in-angular-4poj</guid>
      <description>&lt;p&gt;In this article, I will show you how to create a generic solution to Consume REST API in Angular. I will utilize Typescript Generics in combination with Angular HTTPClient service to eliminate any code redundant, be as &lt;a href="https://en.wikipedia.org/wiki/Open%E2%80%93closed_principle" rel="noopener noreferrer"&gt;DRY&lt;/a&gt; as possible, and follow the &lt;a href="https://en.wikipedia.org/wiki/Open%E2%80%93closed_principle" rel="noopener noreferrer"&gt;Open–closed principle&lt;/a&gt;.&lt;/p&gt;




&lt;h2&gt;
  
  
  Communicating with backend services using HTTPClient
&lt;/h2&gt;

&lt;p&gt;Most applications need to communicate with a remote server over the HTTP protocol, in order to perform the basic &lt;a href="https://en.wikipedia.org/wiki/Create,_read,_update_and_delete" rel="noopener noreferrer"&gt;CRUD&lt;/a&gt; operations. With Angular, you can use &lt;code&gt;HTTPClient&lt;/code&gt; service to achieve this communication easily. As an example, if you need to manage the Posts of your blog, you may have the following service to handle all the operations on the Post resource:&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;This solution is simple and clean, and it even follows the best practices according to the official &lt;a href="https://angular.io/guide/http" rel="noopener noreferrer"&gt;Angular Documentation&lt;/a&gt;. However, applications usually have many resources to manage, for our example, we may have users, comments, reviews, etc. Ideally, each of these resources should have a separate service to handle CRUD operations and communicate with the server, at the end we will have UserService, CommentService, ReviewService. Let's take a look at how the CommentService would look like:&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;





&lt;h2&gt;
  
  
  The Problem
&lt;/h2&gt;

&lt;p&gt;Although the above implementation is very common and widely acceptable, it suffers from two cons:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Code redundant (breaking of the DRY principle): If you compare the &lt;code&gt;PostService&lt;/code&gt; and the &lt;code&gt;CommentService&lt;/code&gt; you will notice how redundant the code is.&lt;/li&gt;
&lt;li&gt;Changes in the server-side, or changes in the way to communicate to the server, require changes in many files (in our case we need to change both &lt;code&gt;PostService&lt;/code&gt; and &lt;code&gt;CommentService&lt;/code&gt; files)&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  Typescript Generics To The Rescue
&lt;/h2&gt;

&lt;p&gt;To solve the above issues let's go ahead and build the following abstract class which will be the base of all the other services:&lt;br&gt;
&lt;/p&gt;
&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;ul&gt;
&lt;li&gt;The new service class is &lt;code&gt;abstract&lt;/code&gt;, which means it can't be instantiated and used directly, but it needs to be extended by other classes.&lt;/li&gt;
&lt;li&gt;We provide one abstract method &lt;code&gt;getResourceUrl&lt;/code&gt;, The class which extends this abstract class must implement this method, and return the URL of the resource as we will see in the following section.&lt;/li&gt;
&lt;li&gt;This is a Generic Class, it is not tied to a specific type, rather the class which extends this abstract class will define the exact type used.&lt;/li&gt;
&lt;li&gt;It has all the needed CRUD operations which we need and used before in the previous service.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Now after we have our abstract generic class, whenever we need a new service we can simply extend this class and implement the only one abstract method &lt;code&gt;getResourceUrl&lt;/code&gt;. so the PostService and CommentService will be as the following:&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;





&lt;h2&gt;
  
  
  Server vs Front-end Model
&lt;/h2&gt;

&lt;p&gt;In most applications, the front-end model doesn't match %100 the server-side model. In other words, the REST API will respond with json object that doesn't match exactly the interface or the class defined in the front-end application. In this case, you need a mapping function to convert between server and front-side mode. This sometimes referred to as serializing/deserializing. &lt;/p&gt;

&lt;p&gt;So, let us extend our base class to provide this mapping functionality. To do so I updated the &lt;code&gt;ResourceService&lt;/code&gt; to look as the following:&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;ul&gt;
&lt;li&gt;I added two new methods:&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;toServerModel&lt;/code&gt;: to convert from the Front-end model to the Server Model, It accepts the resource generic type &lt;code&gt;T&lt;/code&gt; and return &lt;code&gt;any&lt;/code&gt; (json)&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;fromServerModel&lt;/code&gt;: to convert from the Server model to the Front-end Model, it accepts a parameter of the type &lt;code&gt;any&lt;/code&gt; which represent the server response, and return the generic type &lt;code&gt;T&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;I provided a default implementation for both of the two methods &lt;code&gt;toServerModel&lt;/code&gt;, &lt;code&gt;fromServerModel&lt;/code&gt;, so in case no mapping needed, the same object returned by the server will be used as a front-end model. Also since I added a  default implementation, the consumer of this service doesn't have to override or even implement these two methods at all.&lt;/li&gt;

&lt;li&gt;In both &lt;code&gt;getList&lt;/code&gt; and &lt;code&gt;get&lt;/code&gt; methods, I am using the new method &lt;code&gt;fromServerModel&lt;/code&gt;, to map the server response to the front-end Model.&lt;/li&gt;

&lt;li&gt;In both &lt;code&gt;add&lt;/code&gt; and &lt;code&gt;update&lt;/code&gt; methods, I am using &lt;code&gt;toServerModel&lt;/code&gt; to map the front-model to the server model before posting the data to the server.&lt;/li&gt;

&lt;/ul&gt;

&lt;p&gt;Now to consume the new changes we have two cases:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;There is no mapping needed between the server and the front-end model, in this case, we don't have to change anything in the class that extends the &lt;code&gt;resourceService&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;There is some kind of mapping needed between the server and the front-end model, all we need to do is to override &lt;code&gt;toServerModel&lt;/code&gt; and &lt;code&gt;fromServerModel&lt;/code&gt; models in the derived class to address our requirement mappings. For example let's assume, that the &lt;code&gt;PostsService&lt;/code&gt; implemented previously needs to map from timestamp to a js Date object, the PostsService implementation would look like the following:&lt;/li&gt;
&lt;/ol&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;





&lt;h2&gt;
  
  
  Conclusion:
&lt;/h2&gt;

&lt;p&gt;To communicate with a server using the HTTP protocol, you need to use the Angular HTTPClient service. In this article, we implemented a generic extendable solution to allow us to achieve this communication. Our solution is clean, &lt;a href="https://en.wikipedia.org/wiki/Don%27t_repeat_yourself" rel="noopener noreferrer"&gt;DRY&lt;/a&gt;, and follows the &lt;a href="https://en.wikipedia.org/wiki/Open%E2%80%93closed_principle" rel="noopener noreferrer"&gt;Open–closed principle&lt;/a&gt;. We utilized Typescrip Generics, Generic Classes, and we even took into consideration a required mapping between server and front-end model.&lt;/p&gt;

</description>
      <category>angular</category>
      <category>webdev</category>
      <category>typescript</category>
    </item>
    <item>
      <title>Easy Menu Animation Effects with Angular Animations</title>
      <dc:creator>Nichola Alkhouri</dc:creator>
      <pubDate>Mon, 01 Mar 2021 21:07:22 +0000</pubDate>
      <link>https://dev.to/playfulprogramming-angular/easy-menu-animation-effects-with-angular-animations-l6n</link>
      <guid>https://dev.to/playfulprogramming-angular/easy-menu-animation-effects-with-angular-animations-l6n</guid>
      <description>&lt;p&gt;In this article, I will use angular animations to give life to the navigation menu. I will use two types of navigation menus, dropdown, and sidebar. For both, I will animate the menu and the menu items.&lt;/p&gt;




&lt;h2&gt;
  
  
  Dropdown Navigation Menu:
&lt;/h2&gt;

&lt;p&gt;I will start with the simpler example, the dropdown menu. In this animation, I will not use reusable animation, for simplicity reasons. However, I will use reusable animation In the sidebar menu example.&lt;/p&gt;

&lt;p&gt;For this example, I will give the menu element an expand/collapse effect, by animating its height from &lt;code&gt;0px&lt;/code&gt; to the full height when opening the menu, and from the full height to &lt;code&gt;0px&lt;/code&gt; when closing. I will also animate each element with a fading effect and a slight transform on the Y-axis. Additionally, I will add a small delay for each menu item animation.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F0obv1wq87x4j2ab8m5g0.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F0obv1wq87x4j2ab8m5g0.gif" alt="Alt Text" width="800" height="400"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You can find the final code of this animation in this blitz:&lt;br&gt;
&lt;a href="https://stackblitz.com/edit/drop-down-menu-animation" rel="noopener noreferrer"&gt;https://stackblitz.com/edit/drop-down-menu-animation&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Here you can see the code for this animation:&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;ul&gt;
&lt;li&gt;The animation consist of two transitions &lt;code&gt;:enter&lt;/code&gt; and &lt;code&gt;:leave&lt;/code&gt;, these two aliases are used to target the menu element when it enters and leaves the view, you can find more about these two aliases in the &lt;a href="https://angular.io/guide/transition-and-triggers#enter-and-leave-aliases" rel="noopener noreferrer"&gt;official documentation&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;For &lt;code&gt;:enter&lt;/code&gt; trigger, I first define the initial style of the menu &lt;code&gt;{ height: 0, overflow: "hidden" }&lt;/code&gt;. Then query each menu item and give it an initial style as well &lt;code&gt;{ opacity: 0, transform: "translateY(-50px)" }&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Then I am using the &lt;code&gt;sequence&lt;/code&gt; function to run two animations one after another, you can find more about the sequence function in the &lt;a href="https://angular.io/guide/complex-animation-sequences#sequential-vs-parallel-animations" rel="noopener noreferrer"&gt;angular animations official documentation&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;The first animation in the sequence function is the expanding effect of the menu &lt;code&gt;animate("200ms", style({ height: "*" }))&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;The second animation in the &lt;code&gt;sequence&lt;/code&gt; function is the effect of each menu item, for this animation first I am querying each menu item &lt;code&gt;query(".menu-item", [&lt;/code&gt;. then I am using the &lt;code&gt;stagger&lt;/code&gt; function to create a timing gap between each queried item, and  animate each menu item by fading it in, with fixing its position on the Y-axis &lt;code&gt;animate("400ms ease", style({ opacity: 1, transform: "none" }))&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;For the &lt;code&gt;:leave&lt;/code&gt; trigger, I am doing the exact same thing as the &lt;code&gt;:enter&lt;/code&gt; trigger, but with a reversed order.&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  Sidebar Navigation Menu:
&lt;/h2&gt;

&lt;p&gt;For this example, I will make things a little bit more complex but more flexible. I will make the animation reusable. In other words, I will provide some inputs that the consumer of the animation can pass to configure the animation.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Flxp282t4kvx9iqxf84h3.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Flxp282t4kvx9iqxf84h3.gif" alt="Alt Text" width="355" height="434"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You can find the final result of this animation in this blitz:&lt;br&gt;
&lt;a href="https://stackblitz.com/edit/side-menu-animation" rel="noopener noreferrer"&gt;https://stackblitz.com/edit/side-menu-animation&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;And the code bellow:&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;ul&gt;
&lt;li&gt;Very similar to the previous example, I use both &lt;code&gt;:enter&lt;/code&gt; and &lt;code&gt;:leave&lt;/code&gt; triggers, set the initial style of both the menu and the menu items, animate the menu then query and animate each menu item with a timing gap.&lt;/li&gt;
&lt;li&gt;One difference is the animation itself, in this example, I slide the menu container from the left side of the view, and then we do the same for each menu item with a slight delay.&lt;/li&gt;
&lt;li&gt;Also in this example, I used the function &lt;code&gt;animation&lt;/code&gt; which allowed me to create a reusable animation (&lt;a href="https://angular.io/guide/reusable-animations" rel="noopener noreferrer"&gt;more about reusable animations here&lt;/a&gt;), and define some inputs which can be replaced during the runtime of the animation. When using the function &lt;code&gt;animation&lt;/code&gt; to create reusable animation you have to use the function &lt;code&gt;useAnimation&lt;/code&gt; to import the animation into your component.&lt;/li&gt;
&lt;/ul&gt;




&lt;h3&gt;
  
  
  Resources
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Angular Animations Official Documentation: &lt;a href="https://angular.io/guide/animations" rel="noopener noreferrer"&gt;https://angular.io/guide/animations&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Reusable Animations:&lt;a href="https://angular.io/guide/reusable-animations" rel="noopener noreferrer"&gt;https://angular.io/guide/reusable-animations&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;In-Depth guide into animations in Angular by &lt;a href="https://indepth.dev/authors/1070/william" rel="noopener noreferrer"&gt;William Tjondrosuharto&lt;/a&gt;: &lt;a href="https://indepth.dev/posts/1285/in-depth-guide-into-animations-in-angular" rel="noopener noreferrer"&gt;https://indepth.dev/posts/1285/in-depth-guide-into-animations-in-angular&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>angular</category>
      <category>webdev</category>
      <category>typescript</category>
    </item>
    <item>
      <title>Angular Custom Form Control — Simple Color Picker</title>
      <dc:creator>Nichola Alkhouri</dc:creator>
      <pubDate>Tue, 23 Feb 2021 09:14:11 +0000</pubDate>
      <link>https://dev.to/playfulprogramming-angular/angular-custom-form-control-simple-color-picker-4mla</link>
      <guid>https://dev.to/playfulprogramming-angular/angular-custom-form-control-simple-color-picker-4mla</guid>
      <description>&lt;p&gt;In this story, I will show you how to create a custom form control that will integrate with Angular forms API and can be used in both template-driven and model-driven form the same way any native form control is used (e.g &lt;code&gt;&amp;lt;input type="text" ../&amp;gt;&lt;/code&gt;).&lt;/p&gt;

&lt;p&gt;For this purpose we will create a simple color picker component and turn it into a valid reusable form control, after we complete this implementation, you will be able to use your newly created form control in any template-driven or model-driven forms as the following:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Template Driven Approach:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;color-picker&lt;/span&gt; &lt;span class="na"&gt;[(ngModel)]=&lt;/span&gt;&lt;span class="s"&gt;"color"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&amp;lt;/color-picker&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;&lt;strong&gt;Model-driven approach (reactive forms):&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;color-picker&lt;/span&gt; &lt;span class="na"&gt;[formControl]=&lt;/span&gt;&lt;span class="s"&gt;"color"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&amp;lt;/color-picker&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Or&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;color-picker&lt;/span&gt; &lt;span class="na"&gt;formControlName=&lt;/span&gt;&lt;span class="s"&gt;"color"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&amp;lt;/color-picker&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;You can find the full source code in this Blitz, or embedded at the end of the Article&lt;/p&gt;

&lt;p&gt;&lt;a href="https://stackblitz.com/edit/custom-form-field-color-picker?embed=1&amp;amp;file=src/app/app.component.html" rel="noopener noreferrer"&gt;https://stackblitz.com/edit/custom-form-field-color-picker?embed=1&amp;amp;file=src/app/app.component.html&lt;/a&gt;&lt;/p&gt;





&lt;h2&gt;Creating a new component&lt;/h2&gt;





&lt;p&gt;Let's start by creating a new simple component as the following:&lt;/p&gt;




&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;



&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;



&lt;p&gt;A very basic component:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;We have a list of predefined colors named colors, we iterate over each one of these colors in the view and render a &lt;code&gt;div&lt;/code&gt; with a background of that specific color.&lt;/li&gt;
&lt;li&gt;We also define a variable &lt;code&gt;selectedColor&lt;/code&gt; which holds the value of the selected color.&lt;/li&gt;
&lt;li&gt;The user can select a color by clicking on it, this will trigger the method &lt;code&gt;colorClicked&lt;/code&gt; which in turn will assign this color the variable &lt;code&gt;selectedColor&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;On the template, we add the CSS class &lt;code&gt;selected&lt;/code&gt; to the div of the selected color.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Simple but yet not useful in the contexts of a form, there is no way this component can communicate with the surrounding form to inform it of any change in the selected color, and vice-versa there is no way for the form to pass the component a specific color to be selected.&lt;/p&gt;

&lt;p&gt;To fix the above communication problems, let's turn this component into a valid angular form control. To do so we have to do two things:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;We need our component to &lt;strong&gt;Act&lt;/strong&gt; as angular forms API expect it to. To do so we need to implement the &lt;code&gt;ControlValueAccessor&lt;/code&gt; interface in the new component.&lt;/li&gt;
&lt;li&gt;We need to make our component &lt;strong&gt;Visible&lt;/strong&gt; to angular forms API, and we do so by providing our component using the &lt;code&gt;NG_VALUE_ACCESSOR&lt;/code&gt; injection token.&lt;/li&gt;
&lt;/ol&gt;




&lt;h2&gt;
  
  
  Turning our component into valid Angular custom form control
&lt;/h2&gt;



&lt;h3&gt;
  
  
  1- Implementing ControlValueAccessor Interface
&lt;/h3&gt;



&lt;p&gt;To enable angular forms API to interact with our custom form control, we need to implement the &lt;code&gt;ControlValueAccessor&lt;/code&gt; interface, If you take a look at Angular source code on github &lt;a href="https://github.com/angular/angular/blob/master/packages/forms/src/directives/control_value_accessor.ts" rel="noopener noreferrer"&gt;here&lt;/a&gt; you can find this description of the &lt;code&gt;ControlValueAccessor&lt;/code&gt; interface:&lt;br&gt;
&lt;/p&gt;

&lt;blockquote&gt;
&lt;ul&gt;
&lt;li&gt;Defines an interface that acts as a bridge between the Angular forms API and a * native element in the DOM.&lt;p&gt;* Implement this interface to create a custom form control directive * that integrates with Angular forms.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/blockquote&gt;



&lt;p&gt;This interface consists of the following methods which will implement each of them in our component:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;em&gt;WriteValue&lt;/em&gt;: the forms API calls this method whenever the value of the model linked to this control is changed programmatically. In other words this is how Angular telling our component that somehow the value of the form has been changed and we need to react to this change in our component. The method provides us with the new value in its only parameter &lt;code&gt;obj&lt;/code&gt;, and we need to update the UI accordingly, here we only need to assign the new value to the &lt;code&gt;selectedColor&lt;/code&gt; property of the color picker component.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="nf"&gt;writeValue&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;obj&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;any&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt; &lt;span class="k"&gt;void&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;selectedColor&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;obj&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;




&lt;ul&gt;
&lt;li&gt;
&lt;em&gt;registerOnChange&lt;/em&gt;: this method provides us with a way to communicate in the opposite direction, as we saw &lt;strong&gt;WriteValue&lt;/strong&gt; will notify our component of the changes from the outer form, now we need a way to notify the outer form of the changes from inside our component UI (in our case user clicking on a new color). This method provides us in its parameter with a callback function &lt;code&gt;fn&lt;/code&gt; that we should call whenever the value is changed in the UI, to do so we need to save the callback function in a variable, and we use it whenever the user clicks on a new color.
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="k"&gt;private&lt;/span&gt; &lt;span class="nx"&gt;_onChange&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;any&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nf"&gt;registerOnChange&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;fn&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;any&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt; &lt;span class="k"&gt;void&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;_onChange&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;fn&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// Save the callback function&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="nf"&gt;colorClicked&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;string&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;selectedColor&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;color&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;_onChange&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;selectedColor&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// Call the saved callback&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;ul&gt;
&lt;li&gt;
&lt;em&gt;registerOnTouched&lt;/em&gt;: this method is similar to &lt;code&gt;registerOnChange&lt;/code&gt;, it provides us with a callback function to notify the form when the current form controlled is touched, usually, when using an input field, we call the callback on blur, in our example, we consider that the control has been touched once we select any new color.
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="k"&gt;private&lt;/span&gt; &lt;span class="nx"&gt;_onTouch&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;any&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nf"&gt;registerOnTouched&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;fn&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;any&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt; &lt;span class="k"&gt;void&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;_onTouch&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;fn&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;   &lt;span class="c1"&gt;// Save the callback function&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="nf"&gt;colorClicked&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;string&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;selectedColor&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;color&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;_onTouch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// Call the saved callback&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;ul&gt;
&lt;li&gt;
&lt;em&gt;setDisabledState&lt;/em&gt;: the last method to implement, the forms API will call this method whenever the status of the control changes from or to disabled, we are expected to interact on this change and to disable the selection of colors in our component, so we will always save the value returned from this method.
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="k"&gt;private&lt;/span&gt; &lt;span class="nx"&gt;_isDisabled&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;boolean&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nx"&gt;setDisabledState&lt;/span&gt;&lt;span class="p"&gt;?(&lt;/span&gt;&lt;span class="nx"&gt;isDisabled&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;boolean&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt; &lt;span class="k"&gt;void&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;_isDisabled&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;isDisabled&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  2- Providing our component using the &lt;code&gt;NG_VALUE_ACCESSOR&lt;/code&gt; injection token
&lt;/h3&gt;

&lt;p&gt;So far our new component is ready to integrate with Angular forms API, however, one more step is still necessary to allow forms API to recognize our component as a valid form control and interact with it (this interaction is possible because we implemented &lt;code&gt;ControlValueAccessor&lt;/code&gt; interface in the previous step).&lt;/p&gt;

&lt;p&gt;Before we start let’s take a look at the source code of Angular official &lt;code&gt;FormControlDirective&lt;/code&gt; which is responsible for linking our component with the form, and try to understand how this directive builds this link, by looking at the constructor of that directive we find the following:&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="nf"&gt;constructor&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="p"&gt;...&lt;/span&gt;
    &lt;span class="p"&gt;@&lt;/span&gt;&lt;span class="nd"&gt;Optional&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;@&lt;/span&gt;&lt;span class="nd"&gt;Self&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;@&lt;/span&gt;&lt;span class="nd"&gt;Inject&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;NG_VALUE_ACCESSOR&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="nx"&gt;valueAccessors&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;ControlValueAccessor&lt;/span&gt;&lt;span class="p"&gt;[],&lt;/span&gt;
&lt;span class="p"&gt;...)&lt;/span&gt; &lt;span class="p"&gt;{...&lt;/span&gt;
    &lt;span class="nf"&gt;selectValueAccessor&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;valueAccessors&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;  
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Notice the directive is injecting a token &lt;code&gt;NG_VALUE_ACCESSOR&lt;/code&gt; and expect it to provide a list of &lt;code&gt;ControlValueAccessor&lt;/code&gt; (the interface we have just implemented). then this value is being saved and used internally.&lt;/p&gt;

&lt;p&gt;What does this mean to us? this means that if we wanted &lt;code&gt;FormControlDirective&lt;/code&gt; to recognise our component and interact with it, we need to provide our component using the injection token &lt;code&gt;NG_VALUE_ACCESSOR&lt;/code&gt; and to do so we just need to update the options of the Component decorator to be as the following:&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;We configure the component injector using the injection token &lt;code&gt;NG_VALUE_ACCESSOR&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Then we provide our newly created component &lt;code&gt;ColorPickerComponent&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;After that we use &lt;code&gt;forwardRef&lt;/code&gt; (&lt;a href="https://angular.io/api/core/forwardRef" rel="noopener noreferrer"&gt;more about forwardRef&lt;/a&gt;), we do so here because at this point our class is not defined, this function allows us to refer to our component even before we define it.&lt;/li&gt;
&lt;li&gt;Then we use &lt;code&gt;multi:true&lt;/code&gt; to specify that this is one of many other configurations of the same token that could exist on the same element, also this is necessary since it makes the injector returns an array of instances, which is the exact type &lt;code&gt;FormControlDirective&lt;/code&gt; expects in its constructor.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Now our custom form control is ready to be used in any template or model-driven form, we can use it for an example in our &lt;code&gt;AppComponent&lt;/code&gt; as the following:&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;



&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;ul&gt;
&lt;li&gt;We define a &lt;code&gt;formGroup&lt;/code&gt; with two controls title and color, and we add an HTML form element with the directive &lt;code&gt;formGroup&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;The title is just a simple native input, and the color is our newly created color picker component.&lt;/li&gt;
&lt;li&gt;We use &lt;code&gt;formControlName&lt;/code&gt; to link the controls to our form.&lt;/li&gt;
&lt;li&gt;In the end, we are printing the value of the form to confirm that everything is working correctly when we change the form input values.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The final result will be as the following after adding some styling:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fdkiozoou7xl4yetuu22c.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fdkiozoou7xl4yetuu22c.png" alt="angular color picker" width="800" height="400"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Thank you for reading! and remember, never stop learning :)&lt;/p&gt;




&lt;p&gt;&lt;strong&gt;References&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;forwardRef&lt;/code&gt; function, Angular official documentation &lt;a href="https://angular.io/api/core/forwardRef" rel="noopener noreferrer"&gt;https://angular.io/api/core/forwardRef&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;ClassProvider&lt;/code&gt;, Angular official documentation &lt;a href="https://angular.io/api/core/ClassProvider" rel="noopener noreferrer"&gt;https://angular.io/api/core/ClassProvider&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;Basics of reactive forms, Angular official documentation &lt;a href="https://angular.io/guide/reactive-forms" rel="noopener noreferrer"&gt;https://angular.io/guide/reactive-forms&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>angular</category>
      <category>webdev</category>
      <category>typescript</category>
    </item>
    <item>
      <title>Angular Components Unit Test – Common Use Cases</title>
      <dc:creator>Nichola Alkhouri</dc:creator>
      <pubDate>Thu, 18 Feb 2021 22:16:41 +0000</pubDate>
      <link>https://dev.to/playfulprogramming-angular/angular-components-unit-test-common-use-cases-4j3p</link>
      <guid>https://dev.to/playfulprogramming-angular/angular-components-unit-test-common-use-cases-4j3p</guid>
      <description>&lt;p&gt;In this article, I will provide a collection of some important statements used to unit test angular components. You can use any of the following examples directly in your project, or you may prefer to extract some of them into separate helper functions and reuse them all over your project. This article covers testing the following scenarios:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Text interpolation&lt;/li&gt;
&lt;li&gt;User Input Value Change&lt;/li&gt;
&lt;li&gt;Clicking HTML Element&lt;/li&gt;
&lt;li&gt;Access Child (nested) Component&lt;/li&gt;
&lt;li&gt;Content projection&lt;/li&gt;
&lt;li&gt;Component inputs and outputs&lt;/li&gt;
&lt;li&gt;Component Dependencies&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;For this purpose lets assume we have the following simple example component generated using Angular CLI ng g c ExampleComponent:&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;A very basic component consists of one input &lt;code&gt;header&lt;/code&gt; and one property &lt;code&gt;name&lt;/code&gt; displayed in the template using a direct interpolation, a form with one input field and a submit button and one output &lt;code&gt;nameChange&lt;/code&gt; which will emit an event when the user submits the form.&lt;/p&gt;

&lt;p&gt;When you create the above component using Angular CLI you will get automatically a unit test file in the same directory as your component. All the next sections in this article are based on this file, especially the fixture object &lt;code&gt;let fixture: ComponentFixture;&lt;/code&gt;. If you don't use Angular CLI to generate your component file, you may copy the above file in your project, and replace &lt;code&gt;ExampleComponent&lt;/code&gt; with your component class name.&lt;/p&gt;



&lt;h2&gt;
  
  
  Text interpolation: &lt;a&gt;&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;Here we make sure that our component will bind the correct values in the template. Don't forget to call &lt;code&gt;fixture.detectChanges()&lt;/code&gt; which forces the TestBed to perform data binding and update the view.&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;




&lt;h2&gt;
  
  
  User Input Value Change: &lt;a&gt;&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;Here we test that the user interaction with the text input is reflected correctly into our component class. Notice here the use of fakeAsync and tick, because the forms binding involves some asynchronous execution.&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;




&lt;h2&gt;
  
  
  Clicking HTML Element: &lt;a&gt;
&lt;/a&gt;
&lt;/h2&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;




&lt;h2&gt;
  
  
  Access Child (nested) Component: &lt;a&gt;&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;Lets assume that our component contains a nested child component: &lt;/p&gt;

&lt;pre&gt;&lt;code&gt;&amp;lt;app-nested-component&amp;gt;&amp;lt;/app-nested-component&amp;gt;&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;You can access the child component and interact it as the following:&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;





&lt;h2&gt;
  
  
  Content projection: &lt;a&gt;&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;Testing content projection is not straightforward, to do so we need to add a wrapper component around the component being tested and use this wrapper component to pass content through projection. Let's add the following projected content to the view of our component&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;&amp;lt;div class="projected-content&amp;gt; 
    &amp;lt;ng-content select="[description]"&amp;gt;&amp;lt;/ng-content&amp;gt;
&amp;lt;/div&amp;gt;&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;And we can test is by adding a wrapper &lt;code&gt;ExampleWrapperComponent&lt;/code&gt; as the following:&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;





&lt;h2&gt;
  
  
  Component inputs and outputs: &lt;a&gt;&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;You can test component input similar to any normal component property. on the other hand the outputs can be spied on and check if it emits the correct value.&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;





&lt;h2&gt;
  
  
  Component Dependencies: &lt;a&gt;&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt; Components usually have dependencies (services) that help the component to function correctly, and the component needs to interact with these dependencies. When testing a component we need to provide our tests with those dependencies in order to run correctly. Here we need to distinguish between two way of providing a dependency:&lt;/p&gt;

&lt;h3&gt;Dependencies provided in the root injector:&lt;/h3&gt;

&lt;p&gt;When the component has a dependency on a service that is provided in the root injector, you need to provide this service to the TestBed configuration to be available to the component while running the tests:&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;Notice that we are using a mock service here since it is easier and safer to interact with. After that, you will be able to access that service in your tests by calling the &lt;code&gt;inject&lt;/code&gt; method of the &lt;code&gt;TestBed&lt;/code&gt;.&lt;/p&gt;

&lt;h3&gt;Dependencies provided in the component injector:&lt;/h3&gt;

&lt;p&gt;When you have a dependency provided in your component, you can not access it using the TestBed, since it will be available only on the component level of the injection tree. In this case, we need to override the component providers to provide this dependency, and then you can use the component injector to access it.&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;





&lt;p&gt;Do you have or need a specific testing scenario that is not covered by this article? Feel free add it in the comments sections and we will add a use case for you :)&lt;/p&gt;

</description>
      <category>angular</category>
      <category>testing</category>
      <category>webdev</category>
      <category>typescript</category>
    </item>
    <item>
      <title>Optimizing Angular Applications</title>
      <dc:creator>Nichola Alkhouri</dc:creator>
      <pubDate>Fri, 12 Feb 2021 20:35:03 +0000</pubDate>
      <link>https://dev.to/playfulprogramming-angular/optimizing-angular-applications-19l8</link>
      <guid>https://dev.to/playfulprogramming-angular/optimizing-angular-applications-19l8</guid>
      <description>&lt;p&gt;In this article you can find some selectable tips that help you  optimize you angular application, I hope you benefit from it in your projects. Lets start.&lt;/p&gt;

&lt;h2&gt;Critical CSS Inlining:&lt;/h2&gt;

&lt;p&gt;This is a new and cool feature. During the build process, Angular will parse the CSS selectors and try to find a match against the rendered page. Accordingly Angular will decide if that style is part of the Critical Path, and will inline those styles in the HTML. Enabling this feature will improving the &lt;a href="https://web.dev/first-contentful-paint/" rel="noopener noreferrer"&gt;First Contentful Paint&lt;/a&gt; metric of your page.&lt;/p&gt;

&lt;p&gt;You can enable the critical css inlining by adjusting the &lt;code&gt;optimization&lt;/code&gt; browser builder option in angular.json file:&lt;/p&gt;

&lt;pre&gt;"optimization": { 
  "styles": {
    "minify": true,
    "inlineCritical": true // enable critical css inlining
  }
}&lt;/pre&gt;

&lt;p&gt;If you are using Angular Universal to SSR your application, and want to enable Critical CSS Inlining, you need to enable it in &lt;code&gt;server.ts&lt;/code&gt; file&lt;/p&gt;

&lt;pre&gt;  server.engine('html', ngExpressEngine({
    bootstrap: AppServerModule,
    inlineCriticalCss: true
  }));&lt;/pre&gt;








&lt;h2&gt;Font Inlining &lt;/h2&gt;





&lt;p&gt;This is another way to improve the &lt;a href="https://web.dev/first-contentful-paint/" rel="noopener noreferrer"&gt;First Contentful Paint&lt;/a&gt;. You can enable this optimization option If you are using a google font, angular will then inline the google font in the index.html file. This will save you one extra request that the browser needs to do in order to get and render the font.&lt;/p&gt;

&lt;p&gt;You can enable the font inlining also from the &lt;code&gt;optimization&lt;/code&gt; browser builder option in angular.json file:&lt;/p&gt;

&lt;pre&gt;"optimization": { 
  "fonts": {
    "inline": true,// enable font inlining
  }
}&lt;/pre&gt;

&lt;p&gt;You can learn more about the Critical Css Inlining and Font Inlining here &lt;a href="https://angular.io/guide/workspace-config#styles-optimization-options" rel="noopener noreferrer"&gt;https://angular.io/guide/workspace-config#styles-optimization-options&lt;/a&gt;.&lt;/p&gt;








&lt;h2&gt;Use OnPush Change Detection Strategy&lt;/h2&gt;





&lt;p&gt;This strategy prevents angular from running change detection on the entire component subtree, which leads to faster execution. You can enable OnPush change detection in the Component configuration metadata by changing the &lt;code&gt;changeDetection&lt;/code&gt; property as the following:&lt;/p&gt;

&lt;pre&gt;@Component({
    selector: 'my-company',
    templateUrl: './my-company.component.html',
    styleUrls: ['./my-company.component.scss'],
    changeDetection: ChangeDetectionStrategy.OnPush,
})&lt;/pre&gt;

&lt;p&gt;This will deactivate the automatic change detection for this component and its child directives, but keep the possibility to the change detection to be explicitly invoked. The only three cases where angular run change detection on your component in this case are :&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;One of the component @output references has been changed.&lt;/li&gt;
&lt;li&gt;Any Dom event from within the component or one of its child directives.&lt;/li&gt;
&lt;li&gt;Explicitly triggering change detection.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Here you find two in detail article about OnPush change detection: &lt;/p&gt;

&lt;p&gt;&lt;a href="https://netbasal.com/a-comprehensive-guide-to-angular-onpush-change-detection-strategy-5bac493074a4" rel="noopener noreferrer"&gt;https://netbasal.com/a-comprehensive-guide-to-angular-onpush-change-detection-strategy-5bac493074a4&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://blog.angular-university.io/onpush-change-detection-how-it-works/" rel="noopener noreferrer"&gt;https://blog.angular-university.io/onpush-change-detection-how-it-works/&lt;/a&gt;&lt;/p&gt;








&lt;h2&gt;Server Side Rendering with Angular Universal&lt;/h2&gt;





&lt;p&gt;In a &lt;a href="https://nichola.dev/user-experience-core-web-vitals-optimization-angular-universal/" rel="noopener noreferrer"&gt;previous article &lt;/a&gt;I used Angular Universal to server-side render a sample web application in order to improve the user experience and boost Core Web Vitals scores.&lt;/p&gt;

&lt;p&gt;By default, Angular applications are rendered client-side. In other words, the browser loads all the application javascript files, bootstrap the application, made the necessary API calls to get the data to be displayed, and then render the final page. While Angular Universal will execute the application on the server-side, generate a static HTML which will be passed to the client to directly render it to the user. After that, the browser will load the javascript files and re-hydrate the application on the client-side. As a result of this, the application will be rendered much faster, and the user will be able to see the rendered page earlier.&lt;/p&gt;

&lt;p&gt;You can find a full details on how to enable and use Angular Universal here &lt;a href="https://angular.io/guide/universal" rel="noopener noreferrer"&gt;https://angular.io/guide/universal&lt;/a&gt;&lt;/p&gt;








&lt;h2&gt;Use Lazy Loading&lt;/h2&gt;





&lt;h3&gt;Modules Lazy Loading&lt;/h3&gt;





&lt;p&gt;By default, all your Angular code is shipped to the client in one bundle. This bundle could grow in size as you keep adding new features to your application. Luckily Angular supports the ability to lazy loading part of your application. This will improve the initial loading of your application, and so the &lt;a href="https://web.dev/first-contentful-paint/" rel="noopener noreferrer"&gt;Largest Contentful Paint (LCP)&lt;/a&gt;. In meanwhile Angular supports lazy loading through routing. Which means you can lazy load parts of your application as long as it has a separate routing. &lt;/p&gt;

&lt;p&gt;You can find more in details about how to lazy load your angular modules in the official Angular documentation &lt;a href="https://angular.io/guide/lazy-loading-ngmodules" rel="noopener noreferrer"&gt;https://angular.io/guide/lazy-loading-ngmodules&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;Components Lazy Loading&lt;/h3&gt;

&lt;p&gt;With the new Ivy renderer, it is now possible to lazy load Angular Components, which is a great feature. However, it requires some exatra manual work to do it, especially when your component contains some child directives or child components. &lt;/p&gt;

&lt;p&gt;Here you can find a great article on how Components Lazy Loading works &lt;a href="https://johnpapa.net/angular-9-lazy-loading-components/" rel="noopener noreferrer"&gt;https://johnpapa.net/angular-9-lazy-loading-components/&lt;/a&gt;&lt;/p&gt;








&lt;h2&gt;Use the available tools&lt;/h2&gt;





&lt;p&gt;Finally, there are a bunch of tools you can use to measure the performance of your application, which is the first step in the optimization process. Many of these tool also provide you with suggestions on how to fix potential issues in your applications. Probably the most important of these tools are:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;a href="https://developers.google.com/web/tools/lighthouse" rel="noopener noreferrer"&gt;Lighthouse&lt;/a&gt;: an open-source project, shipped with chrome dev tools, with the aim to improve the quality of web pages.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://developers.google.com/speed/pagespeed/insights/" rel="noopener noreferrer"&gt;PageSpeed Insights&lt;/a&gt;: an online tool to generate a performance report of a page on both Desktop and Mobile devices, and provide you with a wide range of suggestions on how to improve and fix the existing issues.&lt;/li&gt;
&lt;/ul&gt;














</description>
    </item>
    <item>
      <title>User Experience and Core Web Vitals Optimization – Angular Universal.</title>
      <dc:creator>Nichola Alkhouri</dc:creator>
      <pubDate>Sun, 07 Feb 2021 16:23:44 +0000</pubDate>
      <link>https://dev.to/playfulprogramming-angular/user-experience-and-core-web-vitals-optimization-angular-universal-ko0</link>
      <guid>https://dev.to/playfulprogramming-angular/user-experience-and-core-web-vitals-optimization-angular-universal-ko0</guid>
      <description>&lt;p&gt;&lt;em&gt;This article was originally published &lt;a href="https://nichola.dev/user-experience-core-web-vitals-optimization-angular-universal/" rel="noopener noreferrer"&gt;here&lt;/a&gt;&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;In this article, I will use Angular Universal to server-side render a sample web application. This would help to improve the user experience and will boost Core Web Vitals scores. At the same time, I will show you that just enabling server-side rendering, without taking any further steps, can negatively impact those Core Web Vitals, and especially CLS.&lt;/p&gt;




&lt;h2&gt;
  
  
  Core Web Vitals and CLS To Measure User Experience
&lt;/h2&gt;

&lt;p&gt;Before we start, if you want to know more about Core Web Vitals, you can visit this page &lt;a href="https://web.dev/vitals/" rel="noopener noreferrer"&gt;https://web.dev/vitals/&lt;/a&gt;. I will provide a brief definition as they appeared in that article.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Web Vitals is an initiative by Google to provide unified guidance for quality signals that are essential to delivering a great user experience on the web. &lt;cite&gt;&lt;a href="https://web.dev/authors/philipwalton" rel="noopener noreferrer"&gt;Philip Walton&lt;/a&gt;&lt;/cite&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;blockquote&gt;
&lt;p&gt;Core Web Vitals are the subset of Web Vitals that apply to all web pages, should be measured by all site owners, and will be surfaced across all Google tools. Each of the Core Web Vitals represents a distinct facet of the user experience, is measurable in the field, and reflects the real-world experience of a critical user-centric outcome.&lt;/p&gt;
&lt;cite&gt;&lt;a href="https://web.dev/authors/philipwalton" rel="noopener noreferrer"&gt;Philip Walton&lt;/a&gt;&lt;/cite&gt;
&lt;/blockquote&gt;

&lt;p&gt;From above, Core Web Vitals help us to measure and optimize the &lt;strong&gt;User Experience&lt;/strong&gt; of our web application. I will focus in this article on one specific signal of those Vitals, the CLS (Cumulative Layout Shift).&lt;/p&gt;

&lt;p&gt;CLS measures the "Visual Stability" of the web application, It reflects how stable your page is, and is affected by the sudden movement or the unexpected changes of the content which happen while the user is reading through. The ideal value of CLS is below "0.1"&lt;strong&gt;. &lt;/strong&gt;You can find more about CLS  in this article &lt;a href="https://web.dev/cls/" rel="noopener noreferrer"&gt;https://web.dev/cls/&lt;/a&gt;.&lt;/p&gt;




&lt;h2&gt;
  
  
  Simple Application Without SSR
&lt;/h2&gt;

&lt;p&gt;Let's first create a simple Angular client-side rendered application, our application will have only one functionality, it will fetch an Article from the server, and then display the articles in the view. We create the application by running:&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 cls-measuer-app
```


Now lets update the app.component.ts, app.component.html to be as the following:

&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;

&lt;p&gt;&amp;lt;ul&amp;gt;&amp;lt;li&amp;gt;In &amp;lt;code&amp;gt;AppComponent&amp;lt;/code&amp;gt; we have an observable &amp;lt;code&amp;gt;article$&amp;lt;/code&amp;gt; which will hold the article object to be displayed.&amp;lt;/li&amp;gt;&amp;lt;li&amp;gt;In &amp;lt;code&amp;gt;ngOnInit&amp;lt;/code&amp;gt; we assign to the return value of the &amp;lt;code&amp;gt;getArticle()&amp;lt;/code&amp;gt; method to the property &amp;lt;code&amp;gt;article$&amp;lt;/code&amp;gt;.&amp;lt;/li&amp;gt;&amp;lt;li&amp;gt;&amp;lt;code&amp;gt;getArticle()&amp;lt;/code&amp;gt; simulates an API call to fetch the article data from the server. It returns a mocked &amp;lt;code&amp;gt;IArticle&amp;lt;/code&amp;gt; object from a json file with a delay of 500 ms. Notice here that the content of the article should be big enough to fill the entire page. This is essential to simulate a real-life example of an article.&amp;lt;/li&amp;gt;&amp;lt;li&amp;gt;We define &amp;lt;code&amp;gt;IArticle&amp;lt;/code&amp;gt; interface, with the properties title, body, and imageUrl.&amp;lt;/li&amp;gt;&amp;lt;li&amp;gt;In the template, we subscribe to the &amp;lt;code&amp;gt;article$&amp;lt;/code&amp;gt; using the async pipe, once resolved we display the data from the returned article object. It is important to specify the &amp;lt;code&amp;gt;height&amp;lt;/code&amp;gt; property of the image. Otherwise, it will have a very big negative impact on the CLS value.&amp;lt;/li&amp;gt;&amp;lt;li&amp;gt;We display a loading indicator while the article is still loading.&amp;lt;/li&amp;gt;&amp;lt;/ul&amp;gt;&lt;/p&gt;

&lt;p&gt;&amp;lt;p&amp;gt;Once we serve and browse the application we will see the header, the footer, and a loading indicator. After half a second the article content would have been loaded and the loading indicator will be replaced with the article content.&amp;lt;/p&amp;gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  Measure Core Web Vitals
&lt;/h3&gt;

&lt;p&gt;To measure the CLS, I am using Web Vitals Chrome extension. I will run the application in production mode and trigger the measuring which will give me the following  results:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fg3iui6tqe4l0obpfy15m.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fg3iui6tqe4l0obpfy15m.png" alt="measures-initial" width="446" height="177"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Notice the value of CLS (0.122) which is higher than the ideal value (0.1). This means that we are not providing a good user experience in our application. The reason behind this is that we are replacing the loading indicator with the article content. This is considered an unexpected change of content and add a negative impact on the CLS signal.&lt;/p&gt;

&lt;p&gt;Luckily this problem is fixable in Angular applications. The solution is to avoid this shifting in the content by providing the final state of the page (after the article is loaded) as fast as possible to the user. We can do so by rendering the page on the server-side using Angular Universal.&lt;/p&gt;

&lt;p&gt;&amp;lt;hr/&amp;gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  Server-side rendering (SSR) with Angular Universal to Improve User Experience
&lt;/h2&gt;

&lt;p&gt;Now we will start solving the above problem. We start by adding Angular Universal to our application to allow server-side rendering of the initial page load. So let's run the following command:&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;ng add @nguniversal/express-engine
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;p&gt;&amp;lt;p&amp;gt;This will prepare the project, installs universal/express-engine, and creates the server-side app module and many other files, you can find more about this command and the files it generates in the &amp;lt;a href="&lt;a href="https://angular.io/guide/universal%22&amp;gt;Angular" rel="noopener noreferrer"&gt;https://angular.io/guide/universal"&amp;amp;gt;Angular&lt;/a&gt; official documentation&amp;lt;/a&amp;gt;.&amp;lt;/p&amp;gt;&lt;/p&gt;

&lt;p&gt;&amp;lt;p&amp;gt;At this point our application supports server-sider rendering, and you can double check this by serving the application using:&amp;lt;/p&amp;gt;&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm run dev:ssr
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;p&gt;open the browser and navigate to the application url, you will now notice that article content is being displayed immediately.&lt;/p&gt;
&lt;h2&gt;
  
  
  That Is Not Enough
&lt;/h2&gt;

&lt;p&gt;&amp;lt;p&amp;gt;Now our application is server-side rendered and is providing the user with the content of the page in no time. However, we still have a problem here. When you run your application, even though you see the Article content immediately, you will notice after a small period of time that the loading indicator will flicker for a moment, and the article content fills the page again. This is a result of the following sequence of execution:&amp;lt;/p&amp;gt;&lt;/p&gt;

&lt;p&gt;&amp;lt;ol&amp;gt;&amp;lt;li&amp;gt;Angular Universal will render the application on the server-side and send the final HTML to the client.&amp;lt;/li&amp;gt;&amp;lt;li&amp;gt;The client receives the rendered HTML and displays it immediately to the user.&amp;lt;/li&amp;gt;&amp;lt;li&amp;gt;The browser loaded all javascript files and re-hydrated our application. After that, the application triggers the article loading process and displays the loading indicator and replaced the indicator with the article content when the loading is finish.&amp;lt;/li&amp;gt;&amp;lt;/ol&amp;gt;&lt;/p&gt;

&lt;p&gt;&amp;lt;p&amp;gt;If we tried to measure the CLS at this time, the result will be event worse than before. First we build our application:&amp;lt;/p&amp;gt;&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm run build:ssr
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;p&gt;Then lets serve it:&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm run serve:ssr
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;p&gt;Now we run the application and takes the measurements again, and her is the result:&lt;br&gt;
&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F7sv2k5gz2cnpybb4kzre.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F7sv2k5gz2cnpybb4kzre.png" alt="measures-after-ssr" width="443" height="177"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Notice that CLS is now (0.168) which is higher than the previous value before enabling SSR. In other words, by enabling SSR we made things even worse than before, fortunately, there is a solution for this problem.&lt;/p&gt;
&lt;h2&gt;
  
  
  TransferState to the rescue
&lt;/h2&gt;

&lt;p&gt;&amp;lt;p&amp;gt;The main reason for the problem we are facing is that our application is loading the article twice, once on the server-side, and then again on the client-side after the browser re-hydrated the application. To fix this we can use &amp;lt;code&amp;gt;TransferState&amp;lt;/code&amp;gt;, and by definition TransferState is:&amp;lt;/p&amp;gt;&lt;/p&gt;

&lt;p&gt;&amp;lt;blockquote class="wp-block-quote"&amp;gt;&amp;lt;p&amp;gt;A key value store that is transferred from the application on the server side to the application on the client side.&amp;lt;/p&amp;gt;&amp;lt;cite&amp;gt;&amp;lt;a href="&lt;a href="https://angular.io/api/platform-browser/TransferState%22&amp;gt;Angular" rel="noopener noreferrer"&gt;https://angular.io/api/platform-browser/TransferState"&amp;amp;gt;Angular&lt;/a&gt; Official Documentation&amp;lt;/a&amp;gt;&amp;lt;/cite&amp;gt;&amp;lt;/blockquote&amp;gt;&lt;/p&gt;

&lt;p&gt;server fetched from the API, and pass it to the client-side application, so we don't have to call the server again on the client-side, to do so we implement the following changes:&amp;lt;/p&amp;gt;&lt;/p&gt;

&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;

&lt;p&gt;&amp;lt;ol&amp;gt;&amp;lt;li&amp;gt;We imported &amp;lt;code&amp;gt;BrowserTransferStateModule&amp;lt;/code&amp;gt; in the &amp;lt;code&amp;gt;AppModule&amp;lt;/code&amp;gt;, and &amp;lt;code&amp;gt;ServerTransferStateModule&amp;lt;/code&amp;gt; in &amp;lt;code&amp;gt;AppServerModule&amp;lt;/code&amp;gt; since the TransferState service is provided within these modules.&amp;lt;/li&amp;gt;&amp;lt;li&amp;gt;We check if the application is running on the server-side &amp;lt;code&amp;gt;if(isPlatformServer(this.platformId))&amp;lt;/code&amp;gt;, we load the article from the API, and we store it in the transfer state &amp;lt;code&amp;gt;this.transferState.set(this.stateKey, article)&amp;lt;/code&amp;gt;.&amp;lt;/li&amp;gt;&amp;lt;li&amp;gt;If the application is running on the client-side, we check if the &amp;lt;code&amp;gt;transferState&amp;lt;/code&amp;gt; has a value from the server &amp;lt;code&amp;gt;this.transferState.hasKey(this.stateKey)&amp;lt;/code&amp;gt;.&amp;lt;/li&amp;gt;&amp;lt;li&amp;gt;If the &amp;lt;code&amp;gt;transferState&amp;lt;/code&amp;gt; has a value, we use it directly, otherwise, we reload the article from the API.&amp;lt;/li&amp;gt;&amp;lt;/ol&amp;gt;&lt;/p&gt;

&lt;p&gt;&amp;lt;p&amp;gt;And thats it, lets build and serve our application again, and measure:&amp;lt;/p&amp;gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Febr18rmpheamycgg5sdx.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Febr18rmpheamycgg5sdx.png" alt="metrict-last-measure" width="444" height="173"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;And now CLS is down to 0, and that is because the content of the page is never change after the initial rendering. &lt;/p&gt;

&lt;p&gt;Overall, if you want to boost your SEO, don't just enable Angular Universal in your application and assume that server-rendering your pages will solve all your SEO problems. Enabling Angular Universal is only the first step. You need to take further steps to make sure that your application is working as intended. and don't forget to measure first then change and compare.&lt;br&gt;
&lt;/p&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

</description>
      <category>angular</category>
      <category>webdev</category>
      <category>typescript</category>
      <category>ux</category>
    </item>
  </channel>
</rss>
