<?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: Jozsef</title>
    <description>The latest articles on DEV Community by Jozsef (@pjozeph).</description>
    <link>https://dev.to/pjozeph</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%2F806280%2F49afbb98-09eb-4069-bebb-5d912acc4fde.jpg</url>
      <title>DEV Community: Jozsef</title>
      <link>https://dev.to/pjozeph</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/pjozeph"/>
    <language>en</language>
    <item>
      <title>When and how to use mergeMap</title>
      <dc:creator>Jozsef</dc:creator>
      <pubDate>Sat, 23 Sep 2023 10:53:49 +0000</pubDate>
      <link>https://dev.to/pjozeph/when-and-how-to-use-mergemap-269c</link>
      <guid>https://dev.to/pjozeph/when-and-how-to-use-mergemap-269c</guid>
      <description>&lt;p&gt;If a developer uses Angular without knowing the power of RxJS the code can turn into a huge mass very fast.&lt;/p&gt;

&lt;p&gt;When the inner observable needs a value from the outer observable, we can and must use mergeMap!&lt;/p&gt;

&lt;p&gt;As a result, we not just gonna have nicer and more readable code, but we can follow the async pipe pattern.&lt;br&gt;
It has also performance advantages if the outer event triggers twice then the first execution will be canceled.&lt;/p&gt;

&lt;h2&gt;
  
  
  With mergeMap
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--BgoW7agN--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/qqbr7gah2d3ra4m3nv4x.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--BgoW7agN--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/qqbr7gah2d3ra4m3nv4x.png" alt="with mergeMap" width="800" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Without mergeMap
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--7A0fKyam--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/nsfnchdz1e8o34ues8tb.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--7A0fKyam--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/nsfnchdz1e8o34ues8tb.png" alt="without mergeMap" width="800" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I am a Full-stack [Angular, Java] contractor/freelancer developer, if you would like to contact me here is my &lt;a href="https://pallagijoe.com/"&gt;website&lt;/a&gt; ! &lt;/p&gt;

&lt;p&gt;You can find me on &lt;a href="https://www.linkedin.com/in/jozsef-pallagi/"&gt;LinkedIn&lt;/a&gt; as well.&lt;/p&gt;

</description>
      <category>rxjs</category>
      <category>angular</category>
      <category>webdev</category>
      <category>programming</category>
    </item>
    <item>
      <title>Subscribe() vs Async Pipes</title>
      <dc:creator>Jozsef</dc:creator>
      <pubDate>Fri, 22 Sep 2023 11:37:15 +0000</pubDate>
      <link>https://dev.to/pjozeph/subscribe-vs-async-pipes-4m9o</link>
      <guid>https://dev.to/pjozeph/subscribe-vs-async-pipes-4m9o</guid>
      <description>&lt;p&gt;When working with observables in Angular, it's considered best practice to utilize pipes because they offer a cleaner and more streamlined approach. Subscribing to a stream directly in a component requires us to manually manage the unsubscription process, typically in the ngOnDestroy() lifecycle method. However, when you use the async pipe, Angular automatically handles subscriptions for you, eliminating the need for implementing ngOnDestroy or manually unsubscribing from observables.&lt;/p&gt;

&lt;p&gt;It's worth noting that there is an issue when using the subscribe() method directly. When working with the OnPush change detection strategy, subscribing to observables in the ngOnInit() method may not work as expected out of the box.&lt;/p&gt;

&lt;p&gt;Although using subscribe() in the template can make the code more readable and understandable, opting for the async pipe is generally more advantageous in terms of performance and helps in avoiding memory leaks.&lt;/p&gt;

&lt;h2&gt;
  
  
  Async pipe
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--LQw9N4Xg--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/xlutnw85xrm66ydv2f6p.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--LQw9N4Xg--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/xlutnw85xrm66ydv2f6p.png" alt="Async pipe angular" width="800" height="838"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Subscribe()
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--mCtsVvGH--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/fibvi3qstntwc0wwwcs2.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--mCtsVvGH--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/fibvi3qstntwc0wwwcs2.png" alt="subscribe angular" width="800" height="1060"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I am a Full-stack [Angular, Java] freelancer developer, if you would like to contact me here is my &lt;a href="https://pallagijoe.com/"&gt;website&lt;/a&gt; ! &lt;/p&gt;

&lt;p&gt;You can find me on &lt;a href="https://www.linkedin.com/in/jozsef-pallagi/"&gt;LinkedIn&lt;/a&gt; as well.&lt;/p&gt;

</description>
      <category>angular</category>
      <category>webdev</category>
      <category>observable</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>Create simple form with Angular</title>
      <dc:creator>Jozsef</dc:creator>
      <pubDate>Fri, 04 Mar 2022 06:39:37 +0000</pubDate>
      <link>https://dev.to/pjozeph/create-simple-form-with-angular-233c</link>
      <guid>https://dev.to/pjozeph/create-simple-form-with-angular-233c</guid>
      <description>&lt;p&gt;This article will introduce how to set a simple form in Angular with &lt;strong&gt;ReactiveFormsModule&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;In order to use ReactiveFormsModule functionalities  you need to import ReactiveFormsModule in your module.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--ONowep87--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/kl5wrt1tt9xwnee1uxgg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--ONowep87--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/kl5wrt1tt9xwnee1uxgg.png" alt="Image description" width="880" height="1102"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;FromGroup containes all the input field value and binds those into a single json object.  These are key values pair, keys can be accessable from the template through FormGroup instance.&lt;br&gt;
FromControl has two optional paramter, the first one the value of the control and the second is the validators.&lt;br&gt;
FormArray can holds  and array of FormControl, its very hand to use when dynamic froms are required in form.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--HDjTsBXb--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/cyo1cgoq7wa5xi36jejc.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--HDjTsBXb--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/cyo1cgoq7wa5xi36jejc.png" alt="form ts " width="880" height="627"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In the template FormGroup and its properties (FormControl, FormArray) can be bindable though &lt;em&gt;formGroup, formControlName, formArryName&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--GpnywCoR--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/7zsbnuqu8gy0gqocy4kq.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--GpnywCoR--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/7zsbnuqu8gy0gqocy4kq.png" alt="form html" width="880" height="627"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This simple demo project can be found under &lt;a href="https://github.com/PJozeph/simple-form-demo"&gt;this repo!&lt;/a&gt;&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Angular Data Bindings</title>
      <dc:creator>Jozsef</dc:creator>
      <pubDate>Sat, 12 Feb 2022 15:47:20 +0000</pubDate>
      <link>https://dev.to/pjozeph/angular-data-binding-cno</link>
      <guid>https://dev.to/pjozeph/angular-data-binding-cno</guid>
      <description>&lt;p&gt;&lt;strong&gt;&lt;em&gt;#prerequisite&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;ng new property-binding-demo&lt;/code&gt;&lt;br&gt;
&lt;code&gt;ng g c home&lt;/code&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;&lt;em&gt;String Interpolation&lt;/em&gt;&lt;/strong&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In Angular, Interpolation is used to display data from component to view (DOM).&lt;/p&gt;

&lt;p&gt;The code in your &lt;strong&gt;&lt;em&gt;home.component.ts&lt;/em&gt;&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;public appName : string  = 'My first string interpolation';
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The &lt;strong&gt;&lt;em&gt;home.component.html&lt;/em&gt;&lt;/strong&gt;  should look like as follows&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;h3&amp;gt;String interpolation&amp;lt;/h3&amp;gt;
&amp;lt;p&amp;gt;{{appName}}&amp;lt;/p&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;em&gt;&lt;strong&gt;Event Binding&lt;/strong&gt;&lt;/em&gt;
If there is any action (mouse click or keyboard action) then the event will be raised. We have different ways to bind an event to DOM element.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The &lt;em&gt;&lt;strong&gt;home.component.ts&lt;/strong&gt;&lt;/em&gt; has a function which receive an event parameter&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;public logEvent(event) {
  console.log(event.target)
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The &lt;em&gt;&lt;strong&gt;home.component.html&lt;/strong&gt;&lt;/em&gt; has to call the &lt;em&gt;logEvent()&lt;/em&gt; method as follows&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;h3&amp;gt;Event Binding&amp;lt;/h3&amp;gt;
&amp;lt;button (click)="logEvent($event)"&amp;gt;Click ME&amp;lt;/button&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;&lt;em&gt;Property binding&lt;/em&gt;&lt;/strong&gt;
This used to bind the data from property of a component to DOM elements. It is denoted by [].
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;public userName : string  = 'Bob';
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the &lt;em&gt;&lt;strong&gt;home.component.html&lt;/strong&gt;&lt;/em&gt;  input element will be initialized with &lt;em&gt;userName&lt;/em&gt; value&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;h3&amp;gt;Property binding&amp;lt;/h3&amp;gt;
&amp;lt;input type="text" [value]="userName"&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
Class Binding&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;It helps to create component with dinamic styling.&lt;/p&gt;

&lt;p&gt;Define css classes in in &lt;em&gt;&lt;strong&gt;home.component.css&lt;/strong&gt;&lt;/em&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;.red {
    background-color: red;
}

.blue {
    background-color: blue;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In &lt;em&gt;&lt;strong&gt;home.component.ts&lt;/strong&gt;&lt;/em&gt; declare a propery and bind one of the css class name and create a function which chnages its value.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;public colorProperty : string = 'red';

public changeColor() {
    this.colorProperty === 'red' ? this.colorProperty = 'blue' : this.colorProperty ='red'
 }

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

&lt;/div&gt;



&lt;p&gt;In &lt;em&gt;&lt;strong&gt;home.component.html&lt;/strong&gt;&lt;/em&gt; bind from component to view as below&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;h3&amp;gt;Style binding&amp;lt;/h3&amp;gt;
&amp;lt;div [style.color]="colorProperty"&amp;gt;
  Style binding content
&amp;lt;/div&amp;gt;
&amp;lt;button (click)='changeColor()'&amp;gt;Change Color&amp;lt;/button&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
Two-way Binding&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Is a two-way interaction, data flows in both ways (from component to views and views to component).&lt;br&gt;
&lt;strong&gt;&lt;em&gt;FormModule&lt;/em&gt;&lt;/strong&gt; do the necessary setup to enable two-way data binding, therefore it is necessary to import.&lt;/p&gt;

&lt;p&gt;Create a separate property for twoWayBinding in &lt;em&gt;&lt;strong&gt;home.component.ts&lt;/strong&gt;&lt;/em&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; public twoWayBinding : string = 'init';
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Update HomeComponent view (home.component.html) as mentioned below&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;h3&amp;gt;Two-way data binding&amp;lt;/h3&amp;gt;
&amp;lt;input type="text" [(ngModel)]="twoWayBinding"/&amp;gt;
{{twoWayBinding}}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Property is bind to form control ngModeldirective and if you enter any text in the textbox, it will bind to the property. &lt;/p&gt;

</description>
      <category>angular</category>
      <category>webdev</category>
    </item>
    <item>
      <title>Integrate Angular 13 with Firebase Auth</title>
      <dc:creator>Jozsef</dc:creator>
      <pubDate>Thu, 03 Feb 2022 10:11:54 +0000</pubDate>
      <link>https://dev.to/pjozeph/integrate-angular-13-with-firebase-auth-38db</link>
      <guid>https://dev.to/pjozeph/integrate-angular-13-with-firebase-auth-38db</guid>
      <description>&lt;p&gt;&lt;a href="https://www.npmjs.com/package/@angular/fire"&gt;@angular/fire&lt;/a&gt; version 7.2.0 and Angular 13.2.0 are used !&lt;/p&gt;

&lt;p&gt;Create a separate module for auth responsibility, the structure will look like this:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Dij5ZYJJ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/iqzwz1et6tw43j4rj4is.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Dij5ZYJJ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/iqzwz1et6tw43j4rj4is.png" alt="auth module structure" width="592" height="572"&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;&lt;code&gt;auth.module.ts&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--jWnTa2ED--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/djbh8zl3slbvw676wetb.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--jWnTa2ED--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/djbh8zl3slbvw676wetb.png" alt="auth.module.ts" width="880" height="649"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;make sure that you have the correct credentials in &lt;code&gt;environment.ts&lt;/code&gt; and &lt;code&gt;environment.prod.ts&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--X7pJKZCo--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/c1i3ay9hh5yexzryamof.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--X7pJKZCo--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/c1i3ay9hh5yexzryamof.png" alt="auth credentials" width="880" height="275"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;select Project settings and you can find there your web app's Firebase configuration&lt;/p&gt;

&lt;p&gt;&lt;code&gt;auth.service.ts&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s---8TGHlqM--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/m9ivp1immszerbfkp94k.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s---8TGHlqM--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/m9ivp1immszerbfkp94k.png" alt="auth.service.ts" width="880" height="508"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I think it is better to handle observables in Angular than promises, that's why I used &lt;code&gt;rxjs from&lt;/code&gt; which create observable from promise, you can read the official docs &lt;a href="https://rxjs.dev/api/index/function/from"&gt;here&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;auth.component.ts&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--u3Zw5Xje--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/cpjn9s9khk08qcoqv14s.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--u3Zw5Xje--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/cpjn9s9khk08qcoqv14s.png" alt="auth component" width="880" height="817"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You can find the app on this &lt;a href="https://github.com/PJozeph/angular-firebase-auth-demo"&gt;repository&lt;/a&gt;&lt;/p&gt;

</description>
      <category>firebase</category>
      <category>angular</category>
      <category>webdev</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>Basics of Angular Lazy Loading</title>
      <dc:creator>Jozsef</dc:creator>
      <pubDate>Wed, 02 Feb 2022 09:08:21 +0000</pubDate>
      <link>https://dev.to/pjozeph/basics-of-angular-lazy-loading-1cl9</link>
      <guid>https://dev.to/pjozeph/basics-of-angular-lazy-loading-1cl9</guid>
      <description>&lt;p&gt;Angular lazy loading means that when the application route loads only those modules will load which is on-demand. If we want to achieve lazy loading it's necessary to break down the application into small separated modules. &lt;/p&gt;

&lt;p&gt;It is a very useful built-in angular feature, as the app complexity grows its size is getting bigger and bigger that leads to slow application, especially on mobile!&lt;/p&gt;




&lt;p&gt;create application: &lt;br&gt;
&lt;code&gt;ng new lazyloading-demo&lt;/code&gt;&lt;br&gt;
create modules&lt;br&gt;
&lt;code&gt;ng g module home&lt;/code&gt;&lt;br&gt;
&lt;code&gt;ng g module products&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;create a separate module for routing paths&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const routes: Routes = [
  {path : '' , component : ProductsComponent}
];

@NgModule({
  imports: [
    RouterModule.forChild(routes),
  ],
  exports: [RouterModule]
})
export class ProductsRoutingModule { }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;import &lt;code&gt;ProductsRoutingModule&lt;/code&gt; into &lt;code&gt;products.module.ts&lt;/code&gt; and the same thing has to be done for &lt;code&gt;Home&lt;/code&gt; module.&lt;br&gt;
Make sure that in routes array has at least one component which point to empty path, that will be the landing page of the module.&lt;/p&gt;






&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const routes: Routes = [
  {path: 'home' , 
     loadChildren : () =&amp;gt; import('./home/home.module').
     then(module =&amp;gt; module.HomeModule)},
  {path : 'products' , 
    loadChildren : () =&amp;gt; import('./products/products.module').
    then(module =&amp;gt; module.ProductsModule)}
];

@NgModule({
  imports: [RouterModule.forRoot(routes)],
  exports: [RouterModule]
})
export class AppRoutingModule { }

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

&lt;/div&gt;



&lt;p&gt;When you query&lt;code&gt;http://localhost:4200/home&lt;/code&gt; in the network tab you can see that &lt;code&gt;src_app_products_products_module_ts.js&lt;/code&gt; loads.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--CNy2WLDq--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/j7npucxsof9aw6od5iqz.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--CNy2WLDq--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/j7npucxsof9aw6od5iqz.png" alt="Lazy loading in the metwork tab" width="880" height="259"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You can find this small demo app on this &lt;a href="https://github.com/PJozeph/angular-lazy-loading-demo"&gt;repository&lt;/a&gt;!&lt;/p&gt;

</description>
      <category>angular</category>
      <category>lazyloading</category>
      <category>routing</category>
    </item>
    <item>
      <title>Angular Lifecycle Hooks</title>
      <dc:creator>Jozsef</dc:creator>
      <pubDate>Mon, 31 Jan 2022 13:33:27 +0000</pubDate>
      <link>https://dev.to/pjozeph/angular-lifecycle-hooks-2ndc</link>
      <guid>https://dev.to/pjozeph/angular-lifecycle-hooks-2ndc</guid>
      <description>&lt;p&gt;Angular lifecycle hooks expose lots of events so developers can define the custom initialization of components.&lt;/p&gt;

&lt;p&gt;First create a new angular app.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;ng new life-cycle-demo&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Create the components :&lt;br&gt;
&lt;code&gt;ng g c cmponents/parent&lt;/code&gt;&lt;br&gt;
&lt;code&gt;ng g c cmponents/children&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;In the parent.componet.html template paste the ng-content &lt;br&gt;
&lt;code&gt;&amp;lt;ng-content&amp;gt;&amp;lt;/ng-content&amp;gt;&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;In the &lt;strong&gt;children.component.html&lt;/strong&gt; we want to define an event which chnages a property value of a children component&lt;br&gt;
&lt;code&gt;&amp;lt;button (click)="changeText()"&amp;gt;Change property value&amp;lt;/button&amp;gt;&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;In the &lt;strong&gt;parent.component.ts&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;export class ParentComponent implements OnChanges,
  OnInit,
  DoCheck,
  AfterContentInit,
  AfterContentChecked,
  AfterViewInit,
  AfterViewChecked {

  constructor() { }

  ngDoCheck(): void {
    console.log("Parent : ngDoCheck()")
  }

  ngOnChanges(changes: SimpleChanges): void {
    console.log("Parent : ngOnChanges")
  }

  ngAfterViewChecked(): void {
    console.log("Parent : ngAfterViewChecked()")
  }

  ngAfterViewInit(): void {
    console.log('Parent: ngAfterViewInit()')
  }

  ngAfterContentChecked(): void {
    console.log('Parent: ngAfterContentChecked()')
  }

  ngAfterContentInit(): void {
    console.log('Parent: ngAfterContentInit()')
  }

  ngOnInit(): void {
    console.log('Parent: ngOnInit() ')
  }

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

&lt;/div&gt;



&lt;p&gt;The intrefaces has to be implemented in the &lt;strong&gt;children.compoent.ts&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;export class ChildrenComponent implements OnInit,
  OnChanges,
  DoCheck,
  AfterContentInit,
  AfterContentChecked,
  AfterViewInit,
  AfterViewChecked {

  componentProperty: string = '';

  constructor() { }

  ngDoCheck(): void {
    console.log('Children ngDoCheck()')
  }

  ngOnChanges(changes: SimpleChanges): void {
    console.log('Children ngDoCheck()')
  }

  ngAfterViewChecked(): void {
    console.log('Children ngAfterViewChecked')
  }

  ngAfterViewInit(): void {
    console.log('Children ngAfterViewInit()')
  }

  ngAfterContentChecked(): void {
    console.log('Children ngAfterContentChecked()')
  }

  ngAfterContentInit(): void {
    console.log('Children ngAfterContentInit()')
  }

  ngOnInit(): void {
    console.log('Children ngOnInit()')
  }

  changeText() {
    this.componentProperty = "text changed"
  }

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

&lt;/div&gt;



&lt;p&gt;In the &lt;strong&gt;app.component.html&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;app-parent&amp;gt;
  &amp;lt;app-children&amp;gt;&amp;lt;/app-children&amp;gt;
&amp;lt;/app-parent&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The expected output&lt;br&gt;
Parent: ngOnInit() &lt;br&gt;
Parent : ngDoCheck()&lt;br&gt;
Children ngOnInit()&lt;br&gt;
Children ngDoCheck()&lt;br&gt;
Children ngAfterContentInit()&lt;br&gt;
Children ngAfterContentChecked()&lt;br&gt;
Parent: ngAfterContentInit()&lt;br&gt;
Parent: ngAfterContentChecked()&lt;br&gt;
Children ngAfterViewInit()&lt;br&gt;
Children ngAfterViewChecked&lt;br&gt;
Parent: ngAfterViewInit()&lt;br&gt;
Parent : ngAfterViewChecked()&lt;/p&gt;

&lt;p&gt;Parent : ngDoCheck()&lt;br&gt;
Children ngDoCheck()&lt;br&gt;
Children ngAfterContentChecked()&lt;br&gt;
Parent: ngAfterContentChecked()&lt;br&gt;
Children ngAfterViewChecked&lt;br&gt;
Parent : ngAfterViewChecked()&lt;/p&gt;

&lt;p&gt;If we triger the action from the Children component the &lt;/p&gt;

&lt;p&gt;Parent: ngDoCheck, &lt;br&gt;
Children: ngDoCheck, &lt;br&gt;
Children ngAfterContentChecked(), &lt;br&gt;
Parent ngAfterContentChecked(), &lt;br&gt;
Children ngAfterViewChecked, &lt;br&gt;
Parent ngAfterViewChecked&lt;/p&gt;

&lt;p&gt;will execute in order.&lt;/p&gt;

&lt;p&gt;There is one action that was not listed which is the &lt;strong&gt;OnDestroy&lt;/strong&gt; this executes the last in the order. Normally Programmers use this to clean up resources like Prmoise or  Subscriptions.&lt;/p&gt;

&lt;p&gt;The most pupular actions are &lt;strong&gt;OnDestroy and OnInit&lt;/strong&gt;. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;OnInit&lt;/strong&gt; runs when a component has fully initialized the developer also can have access to injected properties and it executes only once, and OnChnages and DoCheck execute every change detection. Therefore expensive, heavy code like HTTP calls are placed in the OnInit action.&lt;/p&gt;

</description>
      <category>angular</category>
      <category>programming</category>
    </item>
  </channel>
</rss>
