<?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>Forem: Simi Lika</title>
    <description>The latest articles on Forem by Simi Lika (@slika).</description>
    <link>https://forem.com/slika</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%2F1164343%2F4d13c40f-88ab-412d-b21d-3d7373500af2.png</url>
      <title>Forem: Simi Lika</title>
      <link>https://forem.com/slika</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/slika"/>
    <language>en</language>
    <item>
      <title>Angular Project Structure: Shared Module</title>
      <dc:creator>Simi Lika</dc:creator>
      <pubDate>Wed, 15 May 2024 14:00:34 +0000</pubDate>
      <link>https://forem.com/slika/angular-project-structure-shared-module-3o7b</link>
      <guid>https://forem.com/slika/angular-project-structure-shared-module-3o7b</guid>
      <description>&lt;p&gt;This post provides an overview of the &lt;code&gt;SharedModule&lt;/code&gt; in Angular and guides you on its integration into your project structure. The &lt;code&gt;SharedModule&lt;/code&gt; is designed to hold reusable components, pipes, and other utilities that can be shared across multiple modules in your application.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The module might contain:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;-&lt;code&gt;Components&lt;/code&gt;: Reusable UI components such as headers, footers, buttons, and dialogs.&lt;br&gt;
-&lt;code&gt;Pipes&lt;/code&gt;: Custom pipes for formatting and transforming data.&lt;br&gt;
-&lt;code&gt;Directives&lt;/code&gt;: Custom directives for reusable behaviors.&lt;br&gt;
-&lt;code&gt;Services&lt;/code&gt;: Utilities and helper services that can be used throughout the project.&lt;/p&gt;
&lt;h3&gt;
  
  
  Shared Module Structure
&lt;/h3&gt;

&lt;p&gt;Here's an example structure for the Shared Module:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;/my-angular-project
|-- src
|   |-- app
|   |   |-- shared
|   |   |   |-- shared.module.ts
|   |   |   |-- components
|   |   |   |   |-- header
|   |   |   |   |   |-- header.component.ts
|   |   |   |   |   |-- header.component.html
|   |   |   |   |-- footer
|   |   |   |       |-- footer.component.ts
|   |   |   |       |-- footer.component.html
|   |   |   |-- pipes
|   |   |       |-- capitalize.pipe.ts
|   |   |
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Shared Module Implementation
&lt;/h3&gt;

&lt;h4&gt;
  
  
  1. Creating the Shared Module
&lt;/h4&gt;

&lt;p&gt;Create a shared.module.ts file inside the shared directory.&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="c1"&gt;// src/app/shared/shared.module.ts&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;NgModule&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;@angular/core&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;CommonModule&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;@angular/common&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;HeaderComponent&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;./components/header/header.component&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;FooterComponent&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;./components/footer/footer.component&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;CapitalizePipe&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;./pipes/capitalize.pipe&lt;/span&gt;&lt;span class="dl"&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;NgModule&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
  &lt;span class="na"&gt;declarations&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
    &lt;span class="nx"&gt;HeaderComponent&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="nx"&gt;FooterComponent&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="nx"&gt;CapitalizePipe&lt;/span&gt;
  &lt;span class="p"&gt;],&lt;/span&gt;
  &lt;span class="na"&gt;imports&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
    &lt;span class="nx"&gt;CommonModule&lt;/span&gt;
  &lt;span class="p"&gt;],&lt;/span&gt;
  &lt;span class="na"&gt;exports&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
    &lt;span class="nx"&gt;HeaderComponent&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="nx"&gt;FooterComponent&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="nx"&gt;CapitalizePipe&lt;/span&gt;
  &lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="p"&gt;})&lt;/span&gt;
&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;SharedModule&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;h4&gt;
  
  
  2. Creating Components
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;Header 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="c1"&gt;// src/app/shared/components/header/header.component.ts&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;Component&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;@angular/core&lt;/span&gt;&lt;span class="dl"&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;Component&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
  &lt;span class="na"&gt;selector&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;app-header&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;templateUrl&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;./header.component.html&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
&lt;span class="p"&gt;})&lt;/span&gt;
&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;HeaderComponent&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;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="c"&gt;&amp;lt;!-- src/app/shared/components/header/header.component.html --&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;header&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;h1&amp;gt;&lt;/span&gt;Header Component&lt;span class="nt"&gt;&amp;lt;/h1&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/header&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Footer 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="c1"&gt;// src/app/shared/components/footer/footer.component.ts&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;Component&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;@angular/core&lt;/span&gt;&lt;span class="dl"&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;Component&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
  &lt;span class="na"&gt;selector&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;app-footer&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;templateUrl&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;./footer.component.html&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
&lt;span class="p"&gt;})&lt;/span&gt;
&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;FooterComponent&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;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="c"&gt;&amp;lt;!-- src/app/shared/components/footer/footer.component.html --&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;footer&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;p&amp;gt;&lt;/span&gt;Footer Component&lt;span class="nt"&gt;&amp;lt;/p&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/footer&amp;gt;&lt;/span&gt;

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

&lt;/div&gt;



&lt;h4&gt;
  
  
  3. Creating a Pipe
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// src/app/shared/pipes/capitalize.pipe.ts&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;Pipe&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;PipeTransform&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;@angular/core&lt;/span&gt;&lt;span class="dl"&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;Pipe&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
  &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;capitalize&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
&lt;span class="p"&gt;})&lt;/span&gt;
&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;CapitalizePipe&lt;/span&gt; &lt;span class="k"&gt;implements&lt;/span&gt; &lt;span class="nx"&gt;PipeTransform&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nf"&gt;transform&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;value&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="kr"&gt;string&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;value&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;charAt&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;toUpperCase&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;value&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;slice&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&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;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  4. Export Everything for Easier Imports
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;Index for Components
&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="c1"&gt;// src/app/shared/components/index.ts&lt;/span&gt;
&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;./header/header.component&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;./footer/footer.component&lt;/span&gt;&lt;span class="dl"&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;Index for Pipes
&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="c1"&gt;// src/app/shared/pipes/index.ts&lt;/span&gt;
&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;./capitalize.pipe&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  5. Using the Shared Module
&lt;/h4&gt;

&lt;p&gt;Finally, import the &lt;code&gt;SharedModule&lt;/code&gt; into other modules where you want to use the shared components and pipes.&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="c1"&gt;// src/app/feature/feature.module.ts&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;NgModule&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;@angular/core&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;CommonModule&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;@angular/common&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;SharedModule&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;../shared/shared.module&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;FeatureComponent&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;./feature.component&lt;/span&gt;&lt;span class="dl"&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;NgModule&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
  &lt;span class="na"&gt;declarations&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
    &lt;span class="nx"&gt;FeatureComponent&lt;/span&gt;
  &lt;span class="p"&gt;],&lt;/span&gt;
  &lt;span class="na"&gt;imports&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
    &lt;span class="nx"&gt;CommonModule&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="nx"&gt;SharedModule&lt;/span&gt;
  &lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="p"&gt;})&lt;/span&gt;
&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;FeatureModule&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;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// src/app/app.module.ts&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;BrowserModule&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;@angular/platform-browser&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;NgModule&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;@angular/core&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;AppComponent&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;./app.component&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;SharedModule&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;./shared/shared.module&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;FeatureModule&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;./feature/feature.module&lt;/span&gt;&lt;span class="dl"&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;NgModule&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
  &lt;span class="na"&gt;declarations&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
    &lt;span class="nx"&gt;AppComponent&lt;/span&gt;
  &lt;span class="p"&gt;],&lt;/span&gt;
  &lt;span class="na"&gt;imports&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
    &lt;span class="nx"&gt;BrowserModule&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="nx"&gt;SharedModule&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="nx"&gt;FeatureModule&lt;/span&gt;
  &lt;span class="p"&gt;],&lt;/span&gt;
  &lt;span class="na"&gt;providers&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[],&lt;/span&gt;
  &lt;span class="na"&gt;bootstrap&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;AppComponent&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="p"&gt;})&lt;/span&gt;
&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;AppModule&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;This is a short intro to the &lt;code&gt;SharedModule&lt;/code&gt; for your Angular project. In the next post, we will talk about creating and structuring &lt;code&gt;FeaturesModule&lt;/code&gt;. Happy coding!&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>beginners</category>
      <category>angular</category>
      <category>structure</category>
    </item>
    <item>
      <title>Introducing an open-source platform named StoryForge</title>
      <dc:creator>Simi Lika</dc:creator>
      <pubDate>Sun, 24 Mar 2024 10:19:13 +0000</pubDate>
      <link>https://forem.com/slika/introducing-an-open-source-platform-named-storyforge-i51</link>
      <guid>https://forem.com/slika/introducing-an-open-source-platform-named-storyforge-i51</guid>
      <description>&lt;h2&gt;
  
  
  Unleash Your Inner Storyteller with StoryForge! ✍️✨
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Craft and Unleash Interactive Narratives
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;StoryForge Platform&lt;/strong&gt; is an open-source platform powered by Angular that empowers you to build immersive narrative experiences with branching storylines, choices, and quizzes where you can pass and go to the next step or you can fail and be punished. It provides a user-friendly interface for crafting dynamic stories where players' decisions shape the outcome. right now is at the starting phase.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Here's what StoryForge offers&lt;/strong&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Drag-and-drop interface for easy story creation&lt;/li&gt;
&lt;li&gt;Branching storylines for unique player experiences&lt;/li&gt;
&lt;li&gt;Quizzes and challenges to boost engagement&lt;/li&gt;
&lt;li&gt;Choice-based gameplay with impactful decisions&lt;/li&gt;
&lt;li&gt;Modular components for efficient storytelling&lt;/li&gt;
&lt;li&gt;Multiplatform support for wide accessibility&lt;/li&gt;
&lt;li&gt;Collaborative community for sharing and learning&lt;/li&gt;
&lt;li&gt;Open-source development for constant innovation&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;StoryForge is perfect for&lt;/strong&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;Educators&lt;/code&gt;: Create interactive learning experiences&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;Content Creators&lt;/code&gt;: Develop interactive fiction, games&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;Marketers&lt;/code&gt;: Design engaging campaigns and branded content&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;Trainers&lt;/code&gt;: Build simulations and decision-making exercises&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Join the StoryForge community and&lt;/strong&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Unleash your creativity and craft captivating stories&lt;/li&gt;
&lt;li&gt;Enhance audience engagement and emotional connections&lt;/li&gt;
&lt;li&gt;Promote learning through interactive storytelling&lt;/li&gt;
&lt;li&gt;Collaborate with other creators and developers&lt;/li&gt;
&lt;li&gt;Contribute to an open-source project&lt;/li&gt;
&lt;li&gt;StoryForge is where creativity meets learning and technology!&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Let's build a diverse stories library that engages, challenges, and inspires!&lt;/em&gt;&lt;/strong&gt;&lt;br&gt;
&lt;strong&gt;&lt;em&gt;Find StoryForge on GitHub: &lt;a href="https://github.com/it-illyria/story-forge"&gt;StroyForge&lt;/a&gt;&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>productivity</category>
      <category>angular</category>
      <category>opensource</category>
    </item>
    <item>
      <title>Angular project structure: Core Module</title>
      <dc:creator>Simi Lika</dc:creator>
      <pubDate>Sun, 25 Feb 2024 22:52:45 +0000</pubDate>
      <link>https://forem.com/slika/angular-project-structure-core-module-39d1</link>
      <guid>https://forem.com/slika/angular-project-structure-core-module-39d1</guid>
      <description>&lt;p&gt;This post provides an overview of the &lt;code&gt;core module&lt;/code&gt; in Angular and guides you on its integration into your project structure.&lt;br&gt;
 It serves as the central hub for registering essential services, components, and configurations that are used throughout the entire application. &lt;br&gt;
The module might contain:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;Components&lt;/code&gt;: Here we can have the components for the &lt;code&gt;Footer, Toolbar, navigation, Error-Page, Dashboard, Loader, and Confirmation-Dialog&lt;/code&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;Services&lt;/code&gt;: Here we can have services that are necessary for all the project such as &lt;code&gt;auth-service, authorization-service, cookie-service, load-service, local-storage-service, and rest-api-service&lt;/code&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;Models&lt;/code&gt;: here we have the models that are for the components inside the &lt;code&gt;Core Module&lt;/code&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;Guards&lt;/code&gt;: Here we have guards for to protect routes from being accessed under certain conditions. &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;Interceptors&lt;/code&gt;: They can be used to intercept HTTP requests and responses. They are useful for tasks such as adding headers, handling errors globally, or transforming data before it's sent or received.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;Pipes&lt;/code&gt;: they can be used as customized ones for their reusability into entire project or the places that are needed to be placed.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;
  
  
  &lt;code&gt;Core.module.ts&lt;/code&gt;
&lt;/h2&gt;

&lt;p&gt;We have also the &lt;code&gt;core module&lt;/code&gt; file into the &lt;code&gt;core directory&lt;/code&gt; that is cery important to the project. Here it is how it can look:&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="k"&gt;import&lt;/span&gt;&lt;span class="p"&gt;...&lt;/span&gt;

&lt;span class="p"&gt;@&lt;/span&gt;&lt;span class="nd"&gt;NgModule&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
  &lt;span class="na"&gt;declarations&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[...&lt;/span&gt;&lt;span class="nx"&gt;fromComponents&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;components&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;MenuItemComponent&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;AgeFromDobPipe&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;
  &lt;span class="na"&gt;imports&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;CommonModule&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;HttpClientModule&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;RouterModule&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;MaterialModules&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;NgxPermissionsModule&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;forRoot&lt;/span&gt;&lt;span class="p"&gt;()],&lt;/span&gt;
  &lt;span class="na"&gt;exports&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[...&lt;/span&gt;&lt;span class="nx"&gt;fromComponents&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;components&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;
  &lt;span class="na"&gt;providers&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="na"&gt;provide&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;HTTP_INTERCEPTORS&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;useClass&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;AuthInterceptor&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;multi&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="p"&gt;{&lt;/span&gt;&lt;span class="na"&gt;provide&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;HTTP_INTERCEPTORS&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;useClass&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;ErrorInterceptor&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;multi&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="p"&gt;{&lt;/span&gt;&lt;span class="na"&gt;provide&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;HTTP_INTERCEPTORS&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;useClass&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;LoaderInterceptorService&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;multi&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="p"&gt;]&lt;/span&gt;
&lt;span class="p"&gt;})&lt;/span&gt;
&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;CoreModule&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nf"&gt;constructor&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;SkipSelf&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="nx"&gt;parentModule&lt;/span&gt;&lt;span class="p"&gt;?:&lt;/span&gt; &lt;span class="nx"&gt;CoreModule&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;parentModule&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="k"&gt;throw&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Error&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Core Module is already loaded. Import it in the AppModule only&lt;/span&gt;&lt;span class="dl"&gt;'&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="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And the &lt;code&gt;core module&lt;/code&gt; we can import it into &lt;code&gt;app module&lt;/code&gt;.&lt;br&gt;
The file structure of the &lt;code&gt;core module&lt;/code&gt; we can have it like:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;...
|  |--core/
|  |  |--components/
|  |  |  |--error-page/
|  |  |  |  |--error-page.component.ts/sepc.ts/html/scss/
|  |  |  |--dashboard/
|  |  |  |--toolbar/
|  |  |  |--navigation/
|  |  |  |--confirmation-dialog/
|  |  |  |--loader/
|  |  |--guards/
|  |  |--interceptors/
|  |  |--models/
|  |  |--services/
|  |  |--core.module.ts
...
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is a short intro for the &lt;code&gt;core module&lt;/code&gt; for the project. For the next step we will talk about &lt;code&gt;shared module&lt;/code&gt;.&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>productivity</category>
      <category>angular</category>
      <category>structure</category>
    </item>
    <item>
      <title>Angular Project Structure: Auth Module</title>
      <dc:creator>Simi Lika</dc:creator>
      <pubDate>Fri, 26 Jan 2024 15:27:50 +0000</pubDate>
      <link>https://forem.com/slika/angular-project-structure-auth-module-56fb</link>
      <guid>https://forem.com/slika/angular-project-structure-auth-module-56fb</guid>
      <description>&lt;p&gt;This post provides an overview of the &lt;code&gt;auth module&lt;/code&gt; in Angular and guides you on its integration into your project structure.&lt;br&gt;
Building a web application involves many aspects, and one of the most crucial is user authentication. The &lt;code&gt;auth module&lt;/code&gt; serves as the gatekeeper, ensuring only authorized users access privileged information and functions. &lt;/p&gt;
&lt;h3&gt;
  
  
  What is the &lt;code&gt;auth module&lt;/code&gt;?
&lt;/h3&gt;

&lt;p&gt;The &lt;code&gt;auth module&lt;/code&gt; encapsulates functionalities related to user authentication, login, refresh tokens, session management, and user data handling. It offers several benefits:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;Centralized logic&lt;/code&gt;: Simplifies maintenance and code organization.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;Modular structure&lt;/code&gt;: Easier to test and reuse components.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;Improved security&lt;/code&gt;: Reduces risk of unauthorized access.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3&gt;
  
  
  What functionalities can it include?
&lt;/h3&gt;

&lt;p&gt;The specific functionalities can vary, but common features include:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;Login and logout mechanisms&lt;/code&gt;: Handle user credentials and session management.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;Token handling&lt;/code&gt;: Store and use tokens for secure API access.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;User role management&lt;/code&gt;: Define and enforce access levels for different users.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;Authentication guards&lt;/code&gt;: Protect confidential routes for authorized users.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;Error handling&lt;/code&gt;: Handle invalid credentials, expired tokens, and other issues.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3&gt;
  
  
  Integrating the &lt;code&gt;auth module&lt;/code&gt; into your Angular project structure:
&lt;/h3&gt;
&lt;h4&gt;
  
  
  &lt;strong&gt;Creating the module&lt;/strong&gt;:
&lt;/h4&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    Generate a `new module` with `ng g m auth`.
    Generate a `new route module` with `ng g m auth-routing`.
    Define relevant components within the module folder.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; auth
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;After generating the &lt;code&gt;auth.module.ts&lt;/code&gt; and &lt;code&gt;auth-routing.module.ts&lt;/code&gt; the structure will look like:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;...
|--auth/
|  |--auth.module.ts
|  |--auth-routing.module.ts
...
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  &lt;strong&gt;Components&lt;/strong&gt;:
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;Develop a &lt;code&gt;LoginComponent&lt;/code&gt;, &lt;code&gt;ChangePasswordComponent&lt;/code&gt;, and &lt;code&gt;ForgotPasswordComponent&lt;/code&gt; for user login, forgot password and change password.&lt;/li&gt;
&lt;li&gt;Integrate UI elements like login forms, error messages, and user profile displays.&lt;/li&gt;
&lt;li&gt;Create an &lt;code&gt;index.ts&lt;/code&gt; file for a more smoothly access for the components.
After generating the components and index file the &lt;code&gt;auth module&lt;/code&gt; will look like:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;...
|--auth/
|  |--components/
|  |  |--login/
|  |  |  |--login.component.ts/spec.ts/html/scss
|  |  |--forgot-password/
|  |  |  |--forgot-password.component.ts/spec.ts/html/scss
|  |  |--change-password/
|  |  |  |--change-password.component.ts/spec.ts/html/scss
|  |  |--index.ts
|  |--auth.module.ts
|  |--auth-routing.module.ts
...
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now let's get inside &lt;code&gt;auth module&lt;/code&gt; &lt;/p&gt;

&lt;p&gt;We have the file &lt;code&gt;index.ts&lt;/code&gt; in auth/components directory which plays a crucial role in simplifying imports and exports within the component sub-module.&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="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;LoginComponent&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;./login/login.component&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;ChangePasswordComponent&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;./change-password/change-password.component&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;ForgotPasswordComponent&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;./forgot-password/forgot-password.component&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;components&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="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
  &lt;span class="nx"&gt;LoginComponent&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nx"&gt;ChangePasswordComponent&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nx"&gt;ForgotPasswordComponent&lt;/span&gt;
&lt;span class="p"&gt;]&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;./change-password/change-password.component&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;./login/login.component&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;./forgot-password/forgot-password.component&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And we can then import in into &lt;code&gt;auth.module.ts&lt;/code&gt; as:&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="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;NgModule&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;@angular/core&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;CommonModule&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;@angular/common&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;HttpClientModule&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;@angular/common/http&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;AuthRoutingModule&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;./auth-routing.module&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;SharedModule&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;@shared/shared.module&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="nx"&gt;fromComponents&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;./components&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// the import of 'index.ts' file&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;ChangePasswordComponent&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;./components&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;MatCheckboxModule&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;@angular/material/checkbox&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;ForgotPasswordComponent&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;@auth/components&lt;/span&gt;&lt;span class="dl"&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;NgModule&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
  &lt;span class="na"&gt;entryComponents&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
    &lt;span class="nx"&gt;ChangePasswordComponent&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="p"&gt;],&lt;/span&gt;
 &lt;span class="na"&gt;declarations&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[...&lt;/span&gt;&lt;span class="nx"&gt;fromComponents&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;components&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="c1"&gt;// Implementing the components here&lt;/span&gt;
                &lt;span class="nx"&gt;ForgotPasswordComponent&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;
  &lt;span class="na"&gt;imports&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
    &lt;span class="nx"&gt;CommonModule&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;HttpClientModule&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;AuthRoutingModule&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;SharedModule&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;MatCheckboxModule&lt;/span&gt;
  &lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="p"&gt;})&lt;/span&gt;
&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;AuthModule&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&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="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;For the &lt;code&gt;auth-routing.module.ts&lt;/code&gt; we can update it like this:&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="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;NgModule&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;@angular/core&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;RouterModule&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;Routes&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;@angular/router&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;CommonModule&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;@angular/common&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;LoginComponent&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;./components&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;routes&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;Routes&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
  &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="na"&gt;path&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;''&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;component&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;LoginComponent&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;pathMatch&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;full&lt;/span&gt;&lt;span class="dl"&gt;'&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;NgModule&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
  &lt;span class="na"&gt;declarations&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[],&lt;/span&gt;
  &lt;span class="na"&gt;imports&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;CommonModule&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;RouterModule&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;forChild&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;routes&lt;/span&gt;&lt;span class="p"&gt;)],&lt;/span&gt;
  &lt;span class="na"&gt;exports&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;RouterModule&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="p"&gt;})&lt;/span&gt;
&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;AuthRoutingModule&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;For the &lt;code&gt;services&lt;/code&gt;, &lt;code&gt;intercepors&lt;/code&gt;, &lt;code&gt;guards&lt;/code&gt;, etc.. that are part of &lt;br&gt;
&lt;code&gt;auth module&lt;/code&gt; we will implement them into &lt;code&gt;core module&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;...
|--auth/
&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; |--core/
...
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;For this we will speak more in the next post.&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>productivity</category>
      <category>angular</category>
      <category>structure</category>
    </item>
    <item>
      <title>Angular: The Importance of a Well-Structured Project</title>
      <dc:creator>Simi Lika</dc:creator>
      <pubDate>Thu, 18 Jan 2024 16:23:32 +0000</pubDate>
      <link>https://forem.com/slika/angular-the-importance-of-a-well-structured-project-54ee</link>
      <guid>https://forem.com/slika/angular-the-importance-of-a-well-structured-project-54ee</guid>
      <description>&lt;p&gt;In the dynamic world of software development, an Angular project is more than mere code—it is a complex cityscape of functionalities and features. Imagine the project as a city. A well-structured project, like a planned metropolis, is easy to navigate, efficient, and thrives. A messy one, like a sprawling maze, is confusing, inefficient, and prone to collapse.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Importance of Structure:
&lt;/h2&gt;

&lt;p&gt;Think of your code as the city's infrastructure. A well-organized structure, with clear districts and avenues, makes it easy for developers to:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
Find what they need: No more spending hours hunting for specific files or functions.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Understand the code&lt;/strong&gt;: Components are grouped logically, making their purpose and relationships evident.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Collaborate effectively&lt;/strong&gt;: Developers can work on different parts of the project without stepping on each other's toes.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Debug quickly&lt;/strong&gt;: Isolating issues becomes easier when code is organized into modules and features.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Scale gracefully&lt;/strong&gt;: Adding new features or expanding the project is seamless when the foundation is strong.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In the table below are some challenges and benefits for the Angular project structure:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Challenge&lt;/th&gt;
&lt;th&gt;Description&lt;/th&gt;
&lt;th&gt;Benefit&lt;/th&gt;
&lt;th&gt;Description&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Lost productivity&lt;/td&gt;
&lt;td&gt;Developers waste time searching for files and deciphering code.&lt;/td&gt;
&lt;td&gt;Increased developer productivity&lt;/td&gt;
&lt;td&gt;Less time wasted, more time building amazing features.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Duplication of effort&lt;/td&gt;
&lt;td&gt;Same logic might be implemented in multiple places, leading to inconsistencies.&lt;/td&gt;
&lt;td&gt;Improved code quality&lt;/td&gt;
&lt;td&gt;Cleaner, more consistent code leads to fewer bugs and errors.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Bugs and errors&lt;/td&gt;
&lt;td&gt;Hidden connections and dependencies create hard-to-find problems.&lt;/td&gt;
&lt;td&gt;Enhanced collaboration&lt;/td&gt;
&lt;td&gt;Developers work together efficiently, building a stronger team.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Collaboration nightmares&lt;/td&gt;
&lt;td&gt;Merging code becomes a chaotic battle of conflicting versions.&lt;/td&gt;
&lt;td&gt;Faster debugging&lt;/td&gt;
&lt;td&gt;Issues are identified and fixed quickly, keeping your app running smoothly.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Scaling struggles&lt;/td&gt;
&lt;td&gt;Adding new features becomes a complex and error-prone task.&lt;/td&gt;
&lt;td&gt;Effortless scaling&lt;/td&gt;
&lt;td&gt;Adding new features and growing your project becomes a breeze.&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Investing in a structured Angular project, much like meticulously planning a metropolis, yields dividends in increased productivity, elevated code quality, efficient collaboration, expedited debugging, and painless scalability. This blueprint ensures the project's resilience and longevity in the ever-evolving landscape of software development. Let's delve into the core principles that guide this structure:&lt;/p&gt;

&lt;h2&gt;
  
  
  Feature-based Organization:
&lt;/h2&gt;

&lt;p&gt;Imagine your project as a city. Each feature is a distinct district, with its own set of buildings (components), streets (services and pipes), and resources (data and assets). Grouping files by feature enhances:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Understandability&lt;/strong&gt;: Developers can quickly grasp the functionality of each area, making navigation and comprehension easier.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Separation of Concerns&lt;/strong&gt;: Features are self-contained units, minimizing code dependencies and preventing unintended interactions.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Independent Development&lt;/strong&gt;: Teams can work on different features concurrently, boosting collaboration and project progress.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Feature-based Organization:
&lt;/h2&gt;

&lt;p&gt;Imagine your project as a city. Each feature is a distinct district, with its own set of buildings (components), streets (services and pipes), and resources (data and assets). Grouping files by feature enhances:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Understandability&lt;/strong&gt;: Developers can quickly grasp the functionality of each area, making navigation and comprehension easier.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Separation of Concerns&lt;/strong&gt;: Features are self-contained units, minimizing code dependencies and preventing unintended interactions.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Independent Development&lt;/strong&gt;: Teams can work on different features concurrently, boosting collaboration and project progress.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  This modular approach fosters:
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Reusability&lt;/strong&gt;: Code can be easily shared between features, reducing redundancy and effort.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Decoupling&lt;/strong&gt;: Features are loosely coupled, preventing changes in one from affecting others unintentionally.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Scalability&lt;/strong&gt;: Adding new features becomes a breeze by simply creating new modules.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Component Logic Separation:
&lt;/h2&gt;

&lt;p&gt;Picture components as the individual buildings in each district. They should solely focus on displaying UI elements and handling user interactions. Data retrieval and manipulation belong to dedicated services, acting as the city's hidden utilities. This separation:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Keeps components clean and focused&lt;/strong&gt;: UI logic remains concise and easy to understand.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Promotes testability&lt;/strong&gt;: Components become easier to test in isolation from data dependencies.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Improves maintainability&lt;/strong&gt;: Changes in data handling only affect services, not UI components.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Naming Conventions:
&lt;/h2&gt;

&lt;p&gt;Consistent and descriptive naming acts as the city's signage, guiding developers through the code. Use clear and concise names for:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;** Files**: Reflect the feature or component they contain (e.g., user-profile.component.ts).&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Classes&lt;/strong&gt;: Describe their purpose and functionality (e.g., UserProfileService).&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Components&lt;/strong&gt;: Represent the UI element they display (e.g., UserListComponent).&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Following these conventions promotes:
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Readability&lt;/strong&gt;: Code becomes easier to understand and navigate for everyone.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Search-friendliness&lt;/strong&gt;: Finding specific files and components becomes quicker and more efficient.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Collaboration&lt;/strong&gt;: Consistent naming fosters a shared understanding among developers.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;By applying these core principles, you can transform your Angular project into a well-organized city, where developers thrive and features flourish. Remember, a clean and maintainable structure is the foundation for a successful and scalable application!&lt;/p&gt;

&lt;p&gt;Below is an example of the folder structure of the project:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;/my-angular-project
|-- src
|   |-- app
|   |   |-- auth
|   |   |   |--auth.module.ts
|   |   |   |--auth-routing.module.ts
|   |   |   |--components
|   |   |   |  |--login
|   |   |   |  |   |-- login.component.ts/scss/spec.ts.html
|   |   |   |  |--error-handling
|   |   |   |  |   |-- error-handling.component.ts/scss/spec.ts.html
|   |   |   |  |--sso
|   |   |   |  |   |-- sso.component.ts/scss/spec.ts.html
|   |   |   |  |--index.ts
|   |   |-- core
|   |   |   |-- core.module.ts
|   |   |   |-- components
|   |   |   |  |--dashboard
|   |   |   |  |   |-- daashboard.component.ts/scss/spec.ts.html
|   |   |   |  |--navigation
|   |   |   |  |   |-- menu.ts
|   |   |   |  |   |-- menu-item
|   |   |   |  |   |   |-- menu-item.component.ts/scss/spec.ts.html
|   |   |   |  |   |-- error-handling.component.ts/scss/spec.ts.html
|   |   |   |  |--toolbar
|   |   |   |  |   |-- sso.component.ts/scss/spec.ts.html
|   |   |   |  |--index.ts
|   |   |   |-- services
|   |   |   |   |-- authentication.service.ts
|   |   |   |   |-- data.service.ts
|   |   |   |   |-- ...
|   |   |   |   |-- index.ts
|   |   |   |-- guards
|   |   |   |   |-- ...
|   |   |   |   |-- index.ts
|   |   |   |-- interceptors
|   |   |   |   |-- ...
|   |   |   |   |-- index.ts
|   |   |
|   |   |-- shared
|   |   |   |-- shared.module.ts
|   |   |   |-- constants.ts
|   |   |   |-- components
|   |   |   |   |-- header
|   |   |   |   |   |-- header.component.ts
|   |   |   |   |   |-- header.component.html
|   |   |   |   |
|   |   |   |   |-- footer
|   |   |   |       |-- footer.component.ts
|   |   |   |       |-- footer.component.html
|   |   |   |   |--index.ts
|   |   |   |
|   |   |   |-- pipes
|   |   |       |-- capitalize.pipe.ts
|   |   |       |-- index.ts
|   |   |
|   |   |-- features
|   |       |-- user
|   |       |   |-- user.module.ts
|   |       |   |-- components
|   |       |   |   |-- user-list
|   |       |   |   |   |-- user-list.component.ts
|   |       |   |   |   |-- user-list.component.html
|   |       |   |
|   |       |   |-- services
|   |       |       |-- user.service.ts
|   |       |
|   |       |-- product
|   |           |-- product.module.ts
|   |           |-- components
|   |               |-- product-list
|   |               |   |-- product-list.component.ts
|   |               |   |-- product-list.component.html
|   |               |
|   |               |-- services
|   |                   |-- product.service.ts
|-- assets
|-- environments
|-- ...

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

&lt;/div&gt;



</description>
      <category>webdev</category>
      <category>angular</category>
      <category>structure</category>
      <category>productivity</category>
    </item>
    <item>
      <title>Deferrable Views: A New Performance Boost for Angular Applications</title>
      <dc:creator>Simi Lika</dc:creator>
      <pubDate>Mon, 27 Nov 2023 13:50:34 +0000</pubDate>
      <link>https://forem.com/slika/deferrable-views-a-new-performance-boost-for-angular-applications-1e0e</link>
      <guid>https://forem.com/slika/deferrable-views-a-new-performance-boost-for-angular-applications-1e0e</guid>
      <description>&lt;p&gt;Angular continue to surprise us with it's updates per version. In this new version Angular have also changes it's brand and documentation &lt;a href="https://angular.dev/"&gt;Angular 17&lt;/a&gt;. The major release of Angular Framework came with a number of new features and improvements, including:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;&lt;code&gt;Deferrable views&lt;/code&gt;&lt;/strong&gt;: &lt;br&gt;
Defeferrable views are a new feature that allows Angular to defer the creation of views until they are actually needed. This can improve performance, especially for large applications.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;This groundbreaking feature enables developers to create applications that load views only when they are needed, leading to a noticeable improvement in initial rendering times and overall user experience.&lt;br&gt;
The ability to defer view creation introduces a new level of flexibility and control over how Angular applications load. Developers can now prioritize the rendering of essential content, while deferring the loading of less critical views until the user interacts with the application.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;How to Use Deferrable Views&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Implementing deferrable views in Angular 17 is straightforward. Developers can utilize the defer attribute on template elements to indicate that the view should be created lazily. The loadChildren directive can also be used to defer the loading of external components.&lt;/p&gt;

&lt;p&gt;Here is an example of how to use deferrable views to defer the loading of a component named &lt;code&gt;CommentComponent&lt;/code&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;div&lt;/span&gt; &lt;span class="na"&gt;*ngIf=&lt;/span&gt;&lt;span class="s"&gt;"comment"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;comment&lt;/span&gt; &lt;span class="na"&gt;defer&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&amp;lt;/comment&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this example, the &lt;code&gt;CommentComponent&lt;/code&gt; will only be created when the &lt;code&gt;comment&lt;/code&gt; property is true.&lt;/p&gt;

&lt;p&gt;You can also use a loading block to display placeholder content while the view is being loaded:&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;div&lt;/span&gt; &lt;span class="na"&gt;*ngIf=&lt;/span&gt;&lt;span class="s"&gt;"comment"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;loading&lt;/span&gt; &lt;span class="na"&gt;*ngIf=&lt;/span&gt;&lt;span class="s"&gt;"isLoading"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&amp;lt;/loading&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;comment&lt;/span&gt; &lt;span class="na"&gt;defer&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&amp;lt;/comment&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this example, the &lt;code&gt;loading&lt;/code&gt; block will be displayed until the &lt;code&gt;CommentComponent&lt;/code&gt; is loaded.&lt;/p&gt;

&lt;p&gt;We also can have &lt;strong&gt;Loading Content on Demand&lt;/strong&gt; as an example for an e-commerce website that has a huge content. For that we can take  the sidebar and footer which can be deferred until the user scrolls down the page. This ensures that the most critical content, such as product listings and search bar, are rendered first, providing a faster and more responsive user experience.&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;div&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"container"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;div&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;

  &lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"sidebar"&lt;/span&gt; &lt;span class="na"&gt;*defer=&lt;/span&gt;&lt;span class="s"&gt;"on scroll: 100px"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;

  &lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"footer"&lt;/span&gt; &lt;span class="na"&gt;*defer=&lt;/span&gt;&lt;span class="s"&gt;"on viewport: bottom"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this example, the sidebar and footer are wrapped in *defer directives, indicating that they should be created lazily. The on scroll: 100px trigger specifies that the sidebar should be loaded when the user scrolls down the page by 100px. The on viewport: bottom trigger specifies that the footer should be loaded when the user scrolls to the bottom of the viewport.&lt;/p&gt;

&lt;p&gt;The defer directive also supports other triggers, such as on interaction and on timer, providing developers with flexibility to control when deferred views are loaded.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Benefits of Deferrable Views&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;The introduction of deferrable views brings a multitude of benefits for Angular applications:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;Improved Initial Rendering Times&lt;/code&gt;: By deferring the creation of non-essential views, Angular can focus on rendering the most critical content first, significantly reducing initial rendering times and improving page load performance.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;Enhanced User Experience&lt;/code&gt;: Faster initial rendering leads to a smoother and more responsive user experience, especially for users on slower devices or with limited network connectivity.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;Reduced Memory Usage&lt;/code&gt;: Deferring view creation helps optimize memory usage by only instantiating views when they are actually needed, minimizing the overall memory footprint of the application.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;Flexible View Loading&lt;/code&gt;: Developers gain greater control over view loading, allowing them to prioritize essential content and defer non-essential views based on user interaction or application logic.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Real-World Applications of Deferrable Views&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Deferrable views offer immense potential for optimizing Angular applications across various use cases:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;Lazy Loading of Large Components&lt;/code&gt;: Break down large components into smaller, deferrable chunks to improve initial rendering and reduce memory usage.
&lt;/li&gt;
&lt;/ul&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;app-product-detail&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"product-image"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;img&lt;/span&gt; &lt;span class="na"&gt;src=&lt;/span&gt;&lt;span class="s"&gt;"{{ product.imageUrl }}"&lt;/span&gt; &lt;span class="na"&gt;alt=&lt;/span&gt;&lt;span class="s"&gt;"{{ product.name }}"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;

  &lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"product-details"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;h2&amp;gt;&lt;/span&gt;{{ product.name }}&lt;span class="nt"&gt;&amp;lt;/h2&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;p&amp;gt;&lt;/span&gt;{{ product.description }}&lt;span class="nt"&gt;&amp;lt;/p&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;p&amp;gt;&lt;/span&gt;Price: {{ product.price }}&lt;span class="nt"&gt;&amp;lt;/p&amp;gt;&lt;/span&gt;

    &lt;span class="nt"&gt;&amp;lt;button&amp;gt;&lt;/span&gt;Add to Cart&lt;span class="nt"&gt;&amp;lt;/button&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/app-product-detail&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Breaking Down the Component:&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;app-product-detail&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;app-product-image&lt;/span&gt; &lt;span class="na"&gt;*defer=&lt;/span&gt;&lt;span class="s"&gt;"on init"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;img&lt;/span&gt; &lt;span class="na"&gt;src=&lt;/span&gt;&lt;span class="s"&gt;"{{ product.imageUrl }}"&lt;/span&gt; &lt;span class="na"&gt;alt=&lt;/span&gt;&lt;span class="s"&gt;"{{ product.name }}"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;/app-product-image&amp;gt;&lt;/span&gt;

  &lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"product-details"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;h2&amp;gt;&lt;/span&gt;{{ product.name }}&lt;span class="nt"&gt;&amp;lt;/h2&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;p&amp;gt;&lt;/span&gt;{{ product.description }}&lt;span class="nt"&gt;&amp;lt;/p&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;p&amp;gt;&lt;/span&gt;Price: {{ product.price }}&lt;span class="nt"&gt;&amp;lt;/p&amp;gt;&lt;/span&gt;

    &lt;span class="nt"&gt;&amp;lt;button&amp;gt;&lt;/span&gt;Add to Cart&lt;span class="nt"&gt;&amp;lt;/button&amp;gt;&lt;/span&gt;

    &lt;span class="nt"&gt;&amp;lt;app-product-reviews&lt;/span&gt; &lt;span class="na"&gt;*defer=&lt;/span&gt;&lt;span class="s"&gt;"on interaction: click"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="nt"&gt;&amp;lt;/app-product-reviews&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/app-product-detail&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this example, the &lt;code&gt;app-product-detail&lt;/code&gt; component is now divided into two smaller components: &lt;code&gt;app-product-image&lt;/code&gt; and &lt;code&gt;app-product-reviews&lt;/code&gt;. The &lt;code&gt;app-product-image&lt;/code&gt; component contains the product image, which is essential for initial rendering. The &lt;code&gt;app-product-reviews&lt;/code&gt; component, which contains the product reviews, is deferred until the user clicks on the "Reviews" button.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;Loading Content on Demand&lt;/code&gt;: Defer loading non-essential content, such as sidebars or tabs, until the user interacts with the corresponding elements.
&lt;/li&gt;
&lt;/ul&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;div&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"container"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"main-content"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
    ...
  &lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;

  &lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"sidebar"&lt;/span&gt; &lt;span class="na"&gt;*defer=&lt;/span&gt;&lt;span class="s"&gt;"on interaction: sidebarToggle"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
    ...
  &lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;

  &lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"tabs"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;button&lt;/span&gt; &lt;span class="na"&gt;(click)=&lt;/span&gt;&lt;span class="s"&gt;"activateTab('tab1')"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Tab 1&lt;span class="nt"&gt;&amp;lt;/button&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;button&lt;/span&gt; &lt;span class="na"&gt;(click)=&lt;/span&gt;&lt;span class="s"&gt;"activateTab('tab2')"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Tab 2&lt;span class="nt"&gt;&amp;lt;/button&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;

  &lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"tab-content"&lt;/span&gt; &lt;span class="na"&gt;*defer=&lt;/span&gt;&lt;span class="s"&gt;"on demand: activeTab"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;ng-template&lt;/span&gt; &lt;span class="na"&gt;#tab1&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="nt"&gt;&amp;lt;/ng-template&amp;gt;&lt;/span&gt;

    &lt;span class="nt"&gt;&amp;lt;ng-template&lt;/span&gt; &lt;span class="na"&gt;#tab2&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="nt"&gt;&amp;lt;/ng-template&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this example, the sidebar is wrapped in a &lt;code&gt;*defer&lt;/code&gt; directive with an &lt;code&gt;on interaction: sidebarToggle&lt;/code&gt; trigger. This means that the sidebar will only be loaded when the user clicks on the sidebar toggle button.&lt;/p&gt;

&lt;p&gt;The tabs are also deferrable, using an &lt;code&gt;on demand: activeTab&lt;/code&gt; trigger. This means that only the content of the currently active tab will be loaded. The &lt;code&gt;activateTab&lt;/code&gt; method is used to update the &lt;code&gt;activeTab&lt;/code&gt; property, which in turn triggers the loading of the corresponding tab content&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;Optimizing Mobile Performance&lt;/code&gt;: Prioritize rendering essential content for mobile devices to ensure a seamless user experience on slower networks or devices with limited processing power.
&lt;/li&gt;
&lt;/ul&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;div&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"product-page"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"product-image"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;img&lt;/span&gt; &lt;span class="na"&gt;src=&lt;/span&gt;&lt;span class="s"&gt;"low-res-image.jpg"&lt;/span&gt; &lt;span class="na"&gt;alt=&lt;/span&gt;&lt;span class="s"&gt;"Product thumbnail"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;img&lt;/span&gt; &lt;span class="na"&gt;*defer=&lt;/span&gt;&lt;span class="s"&gt;"on platform: mobile"&lt;/span&gt; &lt;span class="na"&gt;src=&lt;/span&gt;&lt;span class="s"&gt;"high-res-image.jpg"&lt;/span&gt; &lt;span class="na"&gt;alt=&lt;/span&gt;&lt;span class="s"&gt;"Product image"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;

  &lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"product-details"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;h2&amp;gt;&lt;/span&gt;Product Name&lt;span class="nt"&gt;&amp;lt;/h2&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;p&amp;gt;&lt;/span&gt;Product description&lt;span class="nt"&gt;&amp;lt;/p&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;

  &lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"product-animation"&lt;/span&gt; &lt;span class="na"&gt;*defer=&lt;/span&gt;&lt;span class="s"&gt;"on platform: mobile"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this example, a low-resolution thumbnail image is loaded initially, while the high-resolution image is deferred until the user is on a non-mobile device. Similarly, the complex animation is only loaded if the user is on a non-mobile device.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;Improving Search Engine Optimization&lt;/code&gt;: Defer loading non-essential content can enhance search engine optimization by reducing page load times and improving perceived performance.
&lt;/li&gt;
&lt;/ul&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;div&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"container"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;h1&amp;gt;&lt;/span&gt;Product Name&lt;span class="nt"&gt;&amp;lt;/h1&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;p&amp;gt;&lt;/span&gt;Product description&lt;span class="nt"&gt;&amp;lt;/p&amp;gt;&lt;/span&gt;

  &lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"product-reviews"&lt;/span&gt; &lt;span class="na"&gt;*defer=&lt;/span&gt;&lt;span class="s"&gt;"on idle: 5000"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;

  &lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"related-products"&lt;/span&gt; &lt;span class="na"&gt;*defer=&lt;/span&gt;&lt;span class="s"&gt;"on viewport: 75%"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this example, the non-essential content, such as product reviews and related products, is wrapped in &lt;code&gt;*defer&lt;/code&gt; directives. These directives indicate that the content should be loaded lazily, meaning it will only be loaded when the user interacts with the page or after a specified delay.&lt;/p&gt;

&lt;p&gt;The &lt;code&gt;on idle: 5000&lt;/code&gt; trigger specifies that the product reviews should be loaded after 5 seconds of user inactivity. This allows the search engine crawler to quickly index the essential content, while the non-essential content is loaded when the user is more likely to engage with it.&lt;/p&gt;

&lt;p&gt;The &lt;code&gt;on viewport: 75%&lt;/code&gt; trigger specifies that the related products should be loaded when the user scrolls to 75% of the viewport. This ensures that the related products are not loaded immediately, which can reduce the initial page load time, but they are still loaded before the user reaches them, providing a seamless user experience.&lt;/p&gt;

&lt;p&gt;By deferring the loading of non-essential content, the page load time can be reduced, and the perceived performance can be improved, both of which can positively impact SEO.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;Flexibility in Triggering Deferral&lt;/code&gt;: Deferrable views offer a variety of triggers to control when a view is loaded. Besides the &lt;code&gt;on scroll&lt;/code&gt;, &lt;code&gt;on viewport&lt;/code&gt;, &lt;code&gt;on interaction&lt;/code&gt;, and &lt;code&gt;on timer&lt;/code&gt; triggers, you can also use custom triggers to defer loading based on specific conditions or events.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;Optimizing for Different Devices&lt;/code&gt;: Deferrable views can be particularly beneficial for mobile applications, where network bandwidth and processing power are often limited. By deferring loading of less critical content, you can ensure that essential components are rendered first, providing a smoother and more responsive experience for mobile users.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;Enabling Lazy Loading of External Components&lt;/code&gt;: The &lt;code&gt;loadChildren&lt;/code&gt; directive can be used to defer the loading of external components, even when they are not directly part of the template. This allows you to prioritize the loading of essential components and defer the loading of external dependencies until they are actually needed.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;Improving Initial Rendering Times&lt;/code&gt;: Deferrable views contribute to faster initial rendering times by minimizing the amount of content that needs to be loaded at the start. This is especially important for applications with large or complex components.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;Reducing Memory Footprint&lt;/code&gt;: By deferring view creation, you can reduce the overall memory footprint of the application. Only the necessary components are loaded at a given time, minimizing the memory consumption of the application.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;Optimizing for Server-Side Rendering (SSR)&lt;/code&gt;: Deferrable views can be used in conjunction with SSR to improve the perceived performance of server-rendered applications. By deferring the loading of non-essential content, you can ensure that the initial content is rendered quickly, even on slower servers.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;Enhancing Performance for Caching and Code Updates&lt;/code&gt;: Deferrable views can also improve the performance of caching and code updates. By deferring the loading of content that may change frequently, you can reduce the cache invalidation overhead and ensure that the application is updated more efficiently.&lt;/p&gt;

&lt;p&gt;In summary, deferrable views represent a significant advancement in Angular's performance optimization capabilities. By enabling developers to defer view creation until they are actually needed, Angular 17 empowers developers to create applications that load faster, use less memory, and provide a more responsive user experience across a wide range of devices and scenarios.&lt;/p&gt;

</description>
      <category>angular</category>
      <category>webdev</category>
      <category>javascript</category>
    </item>
  </channel>
</rss>
