<?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: Nikhil Sai</title>
    <description>The latest articles on Forem by Nikhil Sai (@nikhil6076).</description>
    <link>https://forem.com/nikhil6076</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%2F1152998%2F2168d419-33a0-45e1-936c-70eff9d61d44.png</url>
      <title>Forem: Nikhil Sai</title>
      <link>https://forem.com/nikhil6076</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/nikhil6076"/>
    <language>en</language>
    <item>
      <title>Modern UI the Easy Way: Using Tailwind CSS with Angular</title>
      <dc:creator>Nikhil Sai</dc:creator>
      <pubDate>Tue, 27 May 2025 09:50:35 +0000</pubDate>
      <link>https://forem.com/nikhil6076/modern-ui-the-easy-way-using-tailwind-css-with-angular-146c</link>
      <guid>https://forem.com/nikhil6076/modern-ui-the-easy-way-using-tailwind-css-with-angular-146c</guid>
      <description>&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;As modern web applications grow in complexity, maintaining a consistent and scalable user interface becomes increasingly challenging. Angular offers a robust structure for building large-scale applications, but when it comes to styling, developers often find themselves juggling between custom CSS, component styles, and UI libraries. Enter Tailwind CSS—a utility-first CSS framework that offers a refreshing approach to building user interfaces directly within your templates.&lt;/p&gt;

&lt;p&gt;In this article, we'll explore how to integrate Tailwind CSS into an Angular project and demonstrate its advantages through practical examples. Whether you're building a single-page application or a large enterprise dashboard, Tailwind can simplify your styling workflow and enhance your design consistency.&lt;/p&gt;




&lt;h2&gt;
  
  
  How to Install Tailwind in an Angular App
&lt;/h2&gt;

&lt;p&gt;To get started, you need an Angular project (Angular 12+ is recommended). Tailwind CSS can be installed via &lt;code&gt;npm&lt;/code&gt; and configured easily with PostCSS.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 1:&lt;/strong&gt; Create or Navigate to Your Angular Project&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;ng new angular-tailwind-demo
cd angular-tailwind-demo
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Step 2:&lt;/strong&gt; Install Tailwind and Dependencies&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm install -D tailwindcss postcss autoprefixer
npx tailwindcss init
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This will generate a tailwind.config.js file in your project.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 3:&lt;/strong&gt; Configure Tailwind to Work with Angular&lt;/p&gt;

&lt;p&gt;In &lt;code&gt;tailwind.config.js&lt;/code&gt;, configure the content paths to include Angular templates:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;module.exports = {
  content: [
    "./src/**/*.{html,ts}",
  ],
  theme: {
    extend: {},
  },
  plugins: [],
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Step 4:&lt;/strong&gt; Add Tailwind Directives to styles.css&lt;/p&gt;

&lt;p&gt;Replace or update &lt;code&gt;src/styles.css&lt;/code&gt; with:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;@tailwind base;
@tailwind components;
@tailwind utilities;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now, restart your dev server:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;ng serve
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You're ready to use Tailwind classes in your Angular templates.&lt;/p&gt;




&lt;h2&gt;
  
  
  Creating Reusable Components with Tailwind
&lt;/h2&gt;

&lt;p&gt;Tailwind allows you to compose styles directly in the template, which improves readability and reduces the need for CSS files. Here's a basic example of a reusable Angular component styled with Tailwind:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;button.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;button class="bg-blue-600 hover:bg-blue-700 text-white font-semibold py-2 px-4 rounded"&amp;gt;
  Click Me
&amp;lt;/button&amp;gt;

button.component.ts

import { Component } from '@angular/core';

@Component({
  selector: 'app-button',
  templateUrl: './button.component.html'
})
export class ButtonComponent {}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This approach keeps your design system inline with your components, making it easy to update and maintain.&lt;/p&gt;

&lt;h2&gt;
  
  
  Comparison: Tailwind vs Angular Material
&lt;/h2&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Feature&lt;/th&gt;
&lt;th&gt;Tailwind CSS&lt;/th&gt;
&lt;th&gt;Angular Material&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Design Flexibility&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;High (customizable utility classes)&lt;/td&gt;
&lt;td&gt;Medium (pre-defined components)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Bundle Size&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Smaller with purging&lt;/td&gt;
&lt;td&gt;Larger due to component libraries&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Learning Curve&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Moderate (class-based syntax)&lt;/td&gt;
&lt;td&gt;Moderate (component APIs)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Theming&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Manual via configuration&lt;/td&gt;
&lt;td&gt;Built-in theming support&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Use Case&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Custom, creative UIs&lt;/td&gt;
&lt;td&gt;Enterprise-level design consistency&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;




&lt;h2&gt;
  
  
  Responsive Design with Tailwind Utilities
&lt;/h2&gt;

&lt;p&gt;Tailwind makes responsive design intuitive with mobile-first utility classes. For example:&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;div class="p-4 sm:p-6 md:p-8 lg:p-10 xl:p-12"&amp;gt;
  Responsive Padding
&amp;lt;/div&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This ensures the padding adjusts based on screen size without writing custom media queries. You can easily adapt layouts and typography using breakpoints like sm, md, lg, xl, and 2xl.&lt;/p&gt;




&lt;h2&gt;
  
  
  Real-World Example: Login Form
&lt;/h2&gt;

&lt;p&gt;Here’s a simple login form using Tailwind in Angular:&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;div class="max-w-sm mx-auto mt-10 p-6 bg-white rounded shadow"&amp;gt;
  &amp;lt;h2 class="text-2xl font-bold mb-4"&amp;gt;Login&amp;lt;/h2&amp;gt;
  &amp;lt;form&amp;gt;
    &amp;lt;input class="w-full p-2 mb-4 border rounded" placeholder="Email" /&amp;gt;
    &amp;lt;input class="w-full p-2 mb-4 border rounded" type="password" placeholder="Password" /&amp;gt;
    &amp;lt;button class="w-full bg-blue-600 hover:bg-blue-700 text-white py-2 rounded"&amp;gt;
      Login
    &amp;lt;/button&amp;gt;
  &amp;lt;/form&amp;gt;
&amp;lt;/div&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This form is visually appealing and fully responsive without writing a single line of CSS.&lt;/p&gt;




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

&lt;p&gt;Tailwind CSS brings a utility-first approach to styling Angular applications, allowing developers to build custom, responsive, and maintainable UIs faster. By integrating Tailwind with Angular, you get the best of both worlds—a powerful front-end framework and a flexible styling toolkit. Whether you're prototyping or building a production-ready app, Tailwind can enhance your workflow and help you deliver consistent user experiences.&lt;/p&gt;

&lt;p&gt;Thank's for your time, see you soon in another one :)&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>angular</category>
      <category>tailwindcss</category>
      <category>ui</category>
    </item>
    <item>
      <title>Building Stunning UIs with Angular and Material Design: A Comprehensive Guide</title>
      <dc:creator>Nikhil Sai</dc:creator>
      <pubDate>Fri, 04 Oct 2024 10:59:47 +0000</pubDate>
      <link>https://forem.com/nikhil6076/building-stunning-uis-with-angular-and-material-design-a-comprehensive-guide-5gm0</link>
      <guid>https://forem.com/nikhil6076/building-stunning-uis-with-angular-and-material-design-a-comprehensive-guide-5gm0</guid>
      <description>&lt;p&gt;If you've ever scrolled through a website and paused just to appreciate its design, you know the impact of a well-crafted User Interface (UI). A great UI is more than just colors and buttons; it’s about creating an experience that’s smooth, intuitive, and pleasant for users. For developers, crafting such an experience can be challenging. But fear not—Angular combined with Material Design can make building stunning UIs easier than you think.&lt;/p&gt;

&lt;p&gt;In this comprehensive guide, we’ll explore how Angular and Material Design work together to create modern, responsive, and visually appealing user interfaces. We’ll also dive into various components that Angular Material offers and see how they can be put into practice to build a beautiful UI. Let’s get started.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;What is Angular and Why Use It?&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Angular is a powerful JavaScript framework maintained by Google, used for building single-page applications (SPAs). Angular simplifies building dynamic web applications with its component-based architecture, where each part of your UI is broken down into manageable, reusable components. This makes scaling and maintaining your UI significantly more straightforward.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Introduction to Material Design&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Material Design is Google’s design language that aims to create consistency across web and mobile applications. It’s inspired by the physical world and its textures—like paper and ink—to make the design more intuitive. Material Design brings a level of depth, movement, and interaction that helps users understand how to use an application effortlessly.&lt;/p&gt;

&lt;p&gt;Angular Material is a library that provides a wide array of UI components adhering to Material Design principles. With Angular Material, developers can use components that are pre-built, beautiful, and fully responsive—allowing them to focus on building amazing applications instead of worrying about designing each component from scratch.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Components Offered by Angular Material&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Angular Material offers a wide range of UI components that help developers create beautiful, functional, and consistent applications. Some of the most popular components include:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Buttons&lt;/strong&gt;: Pre-designed buttons that include several options for colors, icons, and functionality.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Toolbar&lt;/strong&gt;: A flexible container to create app headers and footers.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Sidenav&lt;/strong&gt;: A side navigation drawer that can be toggled open or closed.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Cards&lt;/strong&gt;: Containers that hold information like images, titles, and actions in a visually appealing way.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Forms and Input Fields&lt;/strong&gt;: Components that make creating forms a breeze, with built-in labels, validation, and more.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Lists and Grids&lt;/strong&gt;: Help organize content into clear, logical groupings.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Dialogs and Pop-ups&lt;/strong&gt;: Modals and alert boxes to display additional information without leaving the page.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Tabs&lt;/strong&gt;: Components to organize content into multiple sections using tabs.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Chips&lt;/strong&gt;: Compact elements that represent input, such as tags or selections.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Snack Bars&lt;/strong&gt;: Notifications that briefly appear to inform the user.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Tables&lt;/strong&gt;: Data tables with sorting, filtering, and pagination functionalities.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;These components are just a sample of what Angular Material offers. They make developing a consistent and visually appealing UI straightforward, while also ensuring that the end product meets accessibility and performance standards. Now, let’s put some of these components into practice.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Getting Started with Angular and Material Design&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;To use Angular Material in your project, you first need to install Angular and Angular Material.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Install Angular CLI and Create a New Project:&lt;/strong&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;   npm &lt;span class="nb"&gt;install&lt;/span&gt; &lt;span class="nt"&gt;-g&lt;/span&gt; @angular/cli
   ng new stunning-ui-project
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Add Angular Material to Your Project:&lt;/strong&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;   ng add @angular/material
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This command will guide you through selecting a theme, setting up global typography, and adding animations—all of which are essential parts of Material Design.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Using Angular Material Components in Practice&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Angular Material offers a wide range of ready-to-use UI components. Let's walk through some practical examples of using these components to build a stunning user interface.&lt;/p&gt;

&lt;h4&gt;
  
  
  &lt;strong&gt;1. Creating a Navigation Bar with &lt;code&gt;mat-toolbar&lt;/code&gt;&lt;/strong&gt;
&lt;/h4&gt;

&lt;p&gt;The &lt;code&gt;mat-toolbar&lt;/code&gt; component provides a simple way to create a navigation bar that’s clean, consistent, and visually appealing.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Example:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;mat-toolbar&lt;/span&gt; &lt;span class="na"&gt;color=&lt;/span&gt;&lt;span class="s"&gt;"primary"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;span&amp;gt;&lt;/span&gt;Stunning UI App&lt;span class="nt"&gt;&amp;lt;/span&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;span&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"spacer"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&amp;lt;/span&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;button&lt;/span&gt; &lt;span class="na"&gt;mat-button&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Home&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;mat-button&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;About&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;mat-button&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Contact&lt;span class="nt"&gt;&amp;lt;/button&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/mat-toolbar&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Explanation:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;mat-toolbar&lt;/code&gt; is used to create the navigation bar.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;color="primary"&lt;/code&gt; sets the primary theme color.&lt;/li&gt;
&lt;li&gt;The buttons (&lt;code&gt;mat-button&lt;/code&gt;) are used for easy navigation within the application.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Add styles for &lt;code&gt;.spacer&lt;/code&gt; to align buttons to the right:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nc"&gt;.spacer&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;flex&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;1&lt;/span&gt; &lt;span class="m"&gt;1&lt;/span&gt; &lt;span class="nb"&gt;auto&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;
  
  
  &lt;strong&gt;2. Using Cards for Structured Content with &lt;code&gt;mat-card&lt;/code&gt;&lt;/strong&gt;
&lt;/h4&gt;

&lt;p&gt;Cards are a versatile component that can hold text, images, and action buttons. They’re perfect for showing related pieces of content in a visually appealing manner.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Example: Displaying Product Cards&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;mat-card&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"example-card"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;mat-card-header&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;mat-card-avatar&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"example-header-image"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;mat-card-title&amp;gt;&lt;/span&gt;Product Title&lt;span class="nt"&gt;&amp;lt;/mat-card-title&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;mat-card-subtitle&amp;gt;&lt;/span&gt;Product Subtitle&lt;span class="nt"&gt;&amp;lt;/mat-card-subtitle&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;/mat-card-header&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;img&lt;/span&gt; &lt;span class="na"&gt;mat-card-image&lt;/span&gt; &lt;span class="na"&gt;src=&lt;/span&gt;&lt;span class="s"&gt;"product-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;mat-card-content&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;p&amp;gt;&lt;/span&gt;Product description goes here. It provides the user with a short overview of the product.&lt;span class="nt"&gt;&amp;lt;/p&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;/mat-card-content&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;mat-card-actions&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;button&lt;/span&gt; &lt;span class="na"&gt;mat-button&lt;/span&gt; &lt;span class="na"&gt;color=&lt;/span&gt;&lt;span class="s"&gt;"primary"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Buy Now&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;mat-button&lt;/span&gt;&lt;span class="nt"&gt;&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;/mat-card-actions&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/mat-card&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Explanation:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;mat-card&lt;/code&gt; is a container for organizing content, making it visually appealing.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;mat-card-header&lt;/code&gt;, &lt;code&gt;mat-card-title&lt;/code&gt;, and &lt;code&gt;mat-card-subtitle&lt;/code&gt; help structure the card header.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;mat-card-actions&lt;/code&gt; provides buttons for user actions, such as buying or adding to a cart.&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  &lt;strong&gt;3. Building Forms with Angular Material&lt;/strong&gt;
&lt;/h4&gt;

&lt;p&gt;Forms are the backbone of most web applications. Angular Material makes building forms easy and beautiful.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Example: A Simple Login Form&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;mat-card&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"login-card"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;mat-card-title&amp;gt;&lt;/span&gt;Login&lt;span class="nt"&gt;&amp;lt;/mat-card-title&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;mat-card-content&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;form&amp;gt;&lt;/span&gt;
      &lt;span class="nt"&gt;&amp;lt;mat-form-field&lt;/span&gt; &lt;span class="na"&gt;appearance=&lt;/span&gt;&lt;span class="s"&gt;"outline"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;mat-label&amp;gt;&lt;/span&gt;Username&lt;span class="nt"&gt;&amp;lt;/mat-label&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;input&lt;/span&gt; &lt;span class="na"&gt;matInput&lt;/span&gt; &lt;span class="na"&gt;placeholder=&lt;/span&gt;&lt;span class="s"&gt;"Enter your username"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="nt"&gt;&amp;lt;/mat-form-field&amp;gt;&lt;/span&gt;

      &lt;span class="nt"&gt;&amp;lt;mat-form-field&lt;/span&gt; &lt;span class="na"&gt;appearance=&lt;/span&gt;&lt;span class="s"&gt;"outline"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;mat-label&amp;gt;&lt;/span&gt;Password&lt;span class="nt"&gt;&amp;lt;/mat-label&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;input&lt;/span&gt; &lt;span class="na"&gt;matInput&lt;/span&gt; &lt;span class="na"&gt;type=&lt;/span&gt;&lt;span class="s"&gt;"password"&lt;/span&gt; &lt;span class="na"&gt;placeholder=&lt;/span&gt;&lt;span class="s"&gt;"Enter your password"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="nt"&gt;&amp;lt;/mat-form-field&amp;gt;&lt;/span&gt;

      &lt;span class="nt"&gt;&amp;lt;button&lt;/span&gt; &lt;span class="na"&gt;mat-raised-button&lt;/span&gt; &lt;span class="na"&gt;color=&lt;/span&gt;&lt;span class="s"&gt;"primary"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Login&lt;span class="nt"&gt;&amp;lt;/button&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;/form&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;/mat-card-content&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/mat-card&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Explanation:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;mat-form-field&lt;/code&gt; provides an input wrapper with built-in validation and clear labeling.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;matInput&lt;/code&gt; is used to create an input field styled according to Material Design guidelines.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;mat-raised-button&lt;/code&gt; adds a button with a shadow for visual depth.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Advantages of Using Angular Material&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Angular Material offers numerous benefits, including:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Pre-built, Ready-to-Use Components&lt;/strong&gt;: With Angular Material, you get access to a wide range of ready-made UI components that are both visually appealing and fully functional.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Consistency Across Applications&lt;/strong&gt;: Material Design is known for creating consistent interfaces, which is important for user experience. By using Angular Material, you ensure your application follows established design standards.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Accessibility&lt;/strong&gt;: Angular Material components are built with accessibility in mind, making it easier for users with disabilities to interact with your application.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Responsive Design&lt;/strong&gt;: All Angular Material components are designed to work well on a variety of devices, from desktop screens to mobile phones. Using Angular Flex Layout alongside Angular Material further enhances responsiveness.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Customizable Themes&lt;/strong&gt;: Angular Material allows you to customize themes to match your brand’s colors, ensuring a cohesive visual identity across your application.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Productivity Boost&lt;/strong&gt;: With pre-built components, you spend less time on UI development and more time building the functionality of your application.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Putting It All Together: Building a Dashboard&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Let’s take what we’ve learned and build a simple yet beautiful dashboard.&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;mat-sidenav-container&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"example-container"&lt;/span&gt; &lt;span class="na"&gt;fxFlexFill&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;mat-sidenav&lt;/span&gt; &lt;span class="na"&gt;#sidenav&lt;/span&gt; &lt;span class="na"&gt;mode=&lt;/span&gt;&lt;span class="s"&gt;"side"&lt;/span&gt; &lt;span class="na"&gt;opened&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Sidenav content&lt;span class="nt"&gt;&amp;lt;/mat-sidenav&amp;gt;&lt;/span&gt;

  &lt;span class="nt"&gt;&amp;lt;mat-sidenav-content&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;mat-toolbar&lt;/span&gt; &lt;span class="na"&gt;color=&lt;/span&gt;&lt;span class="s"&gt;"primary"&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;mat-icon-button&lt;/span&gt; &lt;span class="na"&gt;(click)=&lt;/span&gt;&lt;span class="s"&gt;"sidenav.toggle()"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;mat-icon&amp;gt;&lt;/span&gt;menu&lt;span class="nt"&gt;&amp;lt;/mat-icon&amp;gt;&lt;/span&gt;
      &lt;span class="nt"&gt;&amp;lt;/button&amp;gt;&lt;/span&gt;
      &lt;span class="nt"&gt;&amp;lt;span&amp;gt;&lt;/span&gt;Dashboard&lt;span class="nt"&gt;&amp;lt;/span&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;/mat-toolbar&amp;gt;&lt;/span&gt;

    &lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;fxLayout=&lt;/span&gt;&lt;span class="s"&gt;"row wrap"&lt;/span&gt; &lt;span class="na"&gt;fxLayoutGap=&lt;/span&gt;&lt;span class="s"&gt;"20px"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="nt"&gt;&amp;lt;mat-card&lt;/span&gt; &lt;span class="na"&gt;fxFlex=&lt;/span&gt;&lt;span class="s"&gt;"30"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Card 1&lt;span class="nt"&gt;&amp;lt;/mat-card&amp;gt;&lt;/span&gt;
      &lt;span class="nt"&gt;&amp;lt;mat-card&lt;/span&gt; &lt;span class="na"&gt;fxFlex=&lt;/span&gt;&lt;span class="s"&gt;"30"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Card 2&lt;span class="nt"&gt;&amp;lt;/mat-card&amp;gt;&lt;/span&gt;
      &lt;span class="nt"&gt;&amp;lt;mat-card&lt;/span&gt; &lt;span class="na"&gt;fxFlex=&lt;/span&gt;&lt;span class="s"&gt;"30"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Card 3&lt;span class="nt"&gt;&amp;lt;/mat-card&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;/mat-sidenav-content&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/mat-sidenav-container&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Explanation:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;mat-sidenav&lt;/code&gt; creates a side navigation panel that can be toggled on and off.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;mat-toolbar&lt;/code&gt; serves as the top bar of the dashboard, providing branding and navigation options.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;mat-card&lt;/code&gt; components are arranged in a responsive grid layout using Angular Flex Layout.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Advanced Tips for Building Stunning UIs&lt;/strong&gt;
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Customize Themes&lt;/strong&gt;: To create a unique UI that matches your brand, make sure to use Angular Material's built-in theming capabilities. You can define primary, accent, and warning colors&lt;br&gt;
and use the predefined palettes or create your own. This way, you can keep your application visually consistent while giving it a personalized touch.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Use Animations&lt;/strong&gt;: Angular provides built-in animation support, which works well with Angular Material components. Adding animations, such as fade-ins or slide transitions, makes the UI more interactive and engaging for users.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Responsive Grids&lt;/strong&gt;: Use Angular Flex Layout in combination with Angular Material to create responsive, adaptive grids. This ensures that your content looks great on different screen sizes, improving the user experience on mobile devices.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Accessibility First&lt;/strong&gt;: Angular Material components come with many accessibility attributes, but it’s still important to use additional ARIA tags and manage the tab order properly. Ensuring that your app is accessible is a big win for user inclusivity.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Testing&lt;/strong&gt;: Angular Material components support testing with tools like Jasmine and Karma. Testing helps catch bugs or unexpected behaviors in your UI components, leading to a more reliable product.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Getting Creative with Angular Material&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Angular Material components are not just easy to use; they’re flexible enough to create custom, engaging user experiences. Let’s explore some ideas:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Custom Dialogs&lt;/strong&gt;: The &lt;code&gt;mat-dialog&lt;/code&gt; component can be customized to create pop-ups that provide extra information or guide users through a multi-step process. For example, you could create a product tutorial using a series of dialogs.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Dynamic Forms&lt;/strong&gt;: Using Angular Reactive Forms in combination with Material components like &lt;code&gt;mat-form-field&lt;/code&gt;, you can create dynamic forms that adapt based on user input, making your application more interactive.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Data Tables&lt;/strong&gt;: The &lt;code&gt;mat-table&lt;/code&gt; component can be used to build feature-rich data tables with sorting, filtering, and pagination—all necessary when displaying large sets of data. You could further enhance it with custom cell templates to make the table even more engaging.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Beautiful Layouts&lt;/strong&gt;: Combining &lt;code&gt;mat-sidenav&lt;/code&gt;, &lt;code&gt;mat-toolbar&lt;/code&gt;, and &lt;code&gt;mat-list&lt;/code&gt; can help you build a sleek and organized navigation system for your app. For example, a dashboard could feature a sidenav for easy navigation between different features, a toolbar for important actions, and cards for highlighting specific data points.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Conclusion&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Angular Material is an excellent toolkit for developers who want to create visually stunning, modern, and accessible user interfaces. By offering a wide array of components that align with Material Design guidelines, Angular Material simplifies the process of building UIs, allowing you to focus more on functionality and less on design intricacies.&lt;/p&gt;

&lt;p&gt;With the wide range of pre-built components—like cards, toolbars, sidenav, tables, dialogs, and more—you can rapidly develop user interfaces that are clean, intuitive, and responsive. &lt;/p&gt;

&lt;p&gt;Moreover, Angular Material helps you maintain accessibility and consistency across your application, enhancing the overall user experience. We’ve explored practical examples like navigation bars, product cards, and data tables, all of which show the power and versatility of Angular Material.&lt;/p&gt;

&lt;p&gt;Remember, the beauty of a great UI lies not just in colors and aesthetics but in the experience it provides for the user. Angular, combined with Material Design, is the perfect blend of functionality and aesthetics to create a truly exceptional experience. Now, go ahead and start building something amazing.&lt;/p&gt;

&lt;p&gt;Thank's for your time, see you soon in another one :)&lt;/p&gt;

</description>
    </item>
    <item>
      <title>The Evolution of Angular: A Journey from AngularJS to Angular Ivy</title>
      <dc:creator>Nikhil Sai</dc:creator>
      <pubDate>Wed, 04 Sep 2024 07:09:49 +0000</pubDate>
      <link>https://forem.com/nikhil6076/the-evolution-of-angular-a-journey-from-angularjs-to-angular-ivy-5ffg</link>
      <guid>https://forem.com/nikhil6076/the-evolution-of-angular-a-journey-from-angularjs-to-angular-ivy-5ffg</guid>
      <description>&lt;h3&gt;
  
  
  Introduction
&lt;/h3&gt;

&lt;p&gt;Angular has come a long way since its inception, evolving from the groundbreaking yet sometimes challenging AngularJS to the highly optimized and efficient Angular Ivy. In this article, we take a conversational journey through the history of Angular, exploring how it has transformed over the years. Join Ram and Krish as they reflect on the highs, lows, and everything in between, offering insights and anecdotes from their own experiences as developers. Whether you’re a seasoned Angular expert or just starting out, this discussion will give you a fresh perspective on one of the most popular web frameworks today.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Ram&lt;/strong&gt;: Hey Krish, do you ever look back and think about how much Angular has changed over the years? From the early days of AngularJS to what we have now with Angular Ivy, it’s been quite the evolution!&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Krish&lt;/strong&gt;: Oh, definitely, Ram! It’s like watching a baby grow into a mature adult. AngularJS was that baby—full of potential but also full of, let's say, "learning opportunities." Remember how exciting it was to use two-way data binding for the first time?&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Ram&lt;/strong&gt;: Exciting is one word for it! I remember thinking two-way data binding was pure magic. You could just link your model to the view, and everything would sync up. But then, as soon as the app grew a bit, the performance issues started. The whole thing would slow down, and you’d spend hours trying to figure out which binding was causing the problem!&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Krish&lt;/strong&gt;: Right! And don’t even get me started on the digest cycle. It was like AngularJS had this secret inner life, constantly checking for changes. If something went wrong, good luck finding it in the 10,000 digest cycles happening every second!&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Ram&lt;/strong&gt;: Hah, yes! But AngularJS did give us a structured way to build single-page applications. Before that, we were just throwing jQuery around and hoping it would stick. AngularJS gave us directives, controllers, and services—a whole new way to think about web development.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Krish&lt;/strong&gt;: True, AngularJS laid the groundwork, but by the time we hit 2016, the web had changed a lot, and so did the needs of developers. That’s when Angular 2 came in like a breath of fresh air—or maybe a tornado! It was a complete rewrite.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Ram&lt;/strong&gt;: A complete rewrite is right! Angular 2 dropped like a bomb. No more controllers, no more &lt;code&gt;$scope&lt;/code&gt;. Instead, it was all about components and TypeScript. It was a huge shift. At first, I thought, "Why are they making us learn a whole new framework?"&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Krish&lt;/strong&gt;: Exactly! And that was a big jump—moving from JavaScript to TypeScript. But in hindsight, it was the best decision. TypeScript brought in static typing, which helped us catch errors early in development. It was a bit of a learning curve, but once you got the hang of it, everything felt so much more robust.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Ram&lt;/strong&gt;: And then, the updates started coming in fast. Angular 4, Angular 5, Angular 6... It was almost like they were on a mission to confuse us with all these rapid releases. Do you remember the chaos when Angular 4 came out?&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Krish&lt;/strong&gt;: Oh, yeah! Everyone was scratching their heads, thinking, "Wait, what happened to Angular 3?" They just skipped it! The truth was, the core libraries had already reached version 4, so they wanted to keep everything in sync. But it did feel like we missed a version while we were sleeping!&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Ram&lt;/strong&gt;: And with each version, they brought in some cool new features. Angular 4 made our bundles smaller, which was great for performance. Angular 5 improved the build optimizer, making our apps load faster. And then Angular 6 introduced Angular Elements, which allowed us to use Angular components as web components in other projects. That was pretty neat!&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Krish&lt;/strong&gt;: Yeah, and let's not forget about Angular CLI. It was around Angular 6 or so that the CLI really started to shine. They added commands for schematics and libraries, which made setting up new projects and maintaining them so much easier. It was like Angular had finally grown up and realized it needed to help developers manage the mess it was creating.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Ram&lt;/strong&gt;: For sure! And then came Angular 7, 8, and the big one—Angular 9 with Ivy. Ivy was a complete game-changer. Do you remember how we used to struggle with large bundle sizes and slow load times? Ivy turned that around completely.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Krish&lt;/strong&gt;: Absolutely! Ivy was like a superhero swooping in to save the day. It made everything faster and more efficient. Smaller bundle sizes meant our apps loaded quicker, and the new rendering engine was far more efficient. Plus, the debugging experience improved drastically.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Ram&lt;/strong&gt;: Ivy also made working with Angular so much more pleasant. Remember how hard it used to be to figure out error messages before Ivy? It was like trying to read ancient scripts!&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Krish&lt;/strong&gt;: I remember! Now, with Ivy, the error messages are so much clearer. You actually understand what went wrong. And don’t forget about the enhanced testing. Ivy’s approach made our component tests more reliable and easier to write.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Ram&lt;/strong&gt;: Speaking of improvements, do you remember how painful it was to manage forms in AngularJS? We had to manually track each input and handle validation ourselves. Now, with Angular’s Reactive Forms, we get a much more structured and powerful way to build forms.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Krish&lt;/strong&gt;: Oh, Reactive Forms have been a lifesaver! They make complex form validations so much easier to manage. It’s like comparing a bicycle to a sports car. The old way was slow and required a lot of effort, while Reactive Forms handle things so smoothly.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Ram&lt;/strong&gt;: Exactly. And then came Angular 10, 11, 12... Each version kept improving on the last. Angular 10 introduced stricter types for catch errors early. Angular 11 focused on improving the developer experience with updates to the CLI and the Hot Module Replacement (HMR). And Angular 12 pushed even further with new features like inline support for Sass in styles and better support for Webpack 5.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Krish&lt;/strong&gt;: And let’s not forget Angular 13 and 14. They finally gave us optional strict mode by default and brought improvements to Angular Universal, making server-side rendering much more straightforward. Plus, better integration with the latest versions of TypeScript always helps.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Ram&lt;/strong&gt;: True! And Angular 15 and 16 brought more incremental improvements, focusing on enhancing performance and developer experience. The team’s focus on refining and optimizing shows they’re serious about making Angular as developer-friendly as possible.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Krish&lt;/strong&gt;: You know, Ram, it feels like Angular has been growing alongside us, getting better with each release. From those early days of AngularJS to the modern, sleek Angular Ivy, it’s been a journey of continuous improvement.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Ram&lt;/strong&gt;: Absolutely, Krish. It’s like Angular has gone from being a clunky, unrefined tool to a mature and powerful framework. And it's not just the framework itself—it's also the ecosystem. The Angular community, the tooling, the libraries—everything has evolved.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Krish&lt;/strong&gt;: That’s so true! And the best part is, Angular is still evolving. With every new version, there are new features and improvements that make our jobs as developers easier and our apps better. I’m excited to see what’s next in the Angular roadmap!&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Ram&lt;/strong&gt;: Me too! Here’s to more updates, more improvements, and an even better Angular. And to all the developers out there, whether you started with AngularJS or jumped in later, you’re part of this journey. The best is yet to come!&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Krish&lt;/strong&gt;: Cheers to that, Ram! Cheers to the future of Angular!&lt;/p&gt;

&lt;p&gt;Thank's for your time, see you soon in another one :)&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Upgrading Your Angular Application to it's latest</title>
      <dc:creator>Nikhil Sai</dc:creator>
      <pubDate>Fri, 12 Apr 2024 11:23:42 +0000</pubDate>
      <link>https://forem.com/nikhil6076/upgrading-your-angular-application-to-its-latest-33ed</link>
      <guid>https://forem.com/nikhil6076/upgrading-your-angular-application-to-its-latest-33ed</guid>
      <description>&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;Upgrading an Angular application from an older version like Angular 7 to the latest version, Angular 17, can be a challenging task. This article will guide you through the process, highlighting the challenges you might encounter and providing remedies for these issues. We will also consider the impact of Node and npm versions on the upgrade process.&lt;/p&gt;

&lt;h2&gt;
  
  
  Prerequisites
&lt;/h2&gt;

&lt;p&gt;Before starting the upgrade process, ensure that your development environment meets the following requirements:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Node.js&lt;/strong&gt;: Angular 17 requires a Node.js version of 12.20.0 or later. If you're using an older version, you'll need to upgrade Node.js first.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;npm&lt;/strong&gt;: Similarly, ensure that you're using npm version 6.11.0 or later.
You can check your current versions by running &lt;code&gt;node -v&lt;/code&gt; and &lt;code&gt;npm -v&lt;/code&gt; in your terminal.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Step-by-Step Upgrade Process
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Update Your Node.js and npm&lt;/strong&gt;: As mentioned earlier before you can upgrade Angular, you need to ensure that your Node.js and npm versions are compatible with Angular 17. You can update Node.js by downloading the latest version from the official Node.js website. To update npm, you can run the command &lt;code&gt;npm install -g npm&lt;/code&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Update Angular CLI&lt;/strong&gt;: The next step is to update your Angular CLI. You can do this by running the command &lt;code&gt;npm install -g @angular/cli@latest&lt;/code&gt;. This command will update your global Angular CLI to the latest version.&lt;br&gt;
For example, if you're using Angular CLI version 7, running this command will upgrade it to version 17.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Update Angular Packages&lt;/strong&gt;: Now you can update the Angular packages in your project. Run the command &lt;code&gt;ng update @angular/core@latest&lt;/code&gt;. This command will update all the Angular packages in your project to their latest versions.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Challenges and Remedies
&lt;/h2&gt;

&lt;p&gt;During the upgrade process, you might encounter several challenges. Here are some common ones and their remedies:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Breaking Changes&lt;/strong&gt;: Angular 17 might introduce breaking changes that affect your application. To remedy this, refer to the Angular Update Guide, which provides information on breaking changes and how to handle them.&lt;br&gt;
For example, if a method you're using in your application has been removed in Angular 17, the Angular Update Guide will provide information on what method you should use instead.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Deprecated APIs&lt;/strong&gt;: Some APIs that your application uses might be deprecated in Angular 17. In this case, you'll need to update your application to use the new APIs.&lt;br&gt;
For example, if you're using the &lt;code&gt;Http&lt;/code&gt; module in your application, you'll need to replace it with the &lt;code&gt;HttpClient&lt;/code&gt; module, as the &lt;code&gt;Http&lt;/code&gt; module has been deprecated.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Package Incompatibilities&lt;/strong&gt;: Some npm packages that your application depends on might not be compatible with Angular 17. You might need to update these packages or find alternatives.&lt;br&gt;
For example, if you're using a package that hasn't been updated to work with Angular 17, you might need to find an alternative package that provides the same functionality and is compatible with Angular 17.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Note&lt;/strong&gt;: Always back up your code before starting the upgrade process and thoroughly test your application after the upgrade to ensure everything works as expected. &lt;/p&gt;

&lt;p&gt;Thank's for your time, see you soon in another one :)&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>beginners</category>
      <category>angular</category>
      <category>webdev</category>
    </item>
    <item>
      <title>Angular at Scale: Introduction to Micro Frontend Architecture</title>
      <dc:creator>Nikhil Sai</dc:creator>
      <pubDate>Mon, 08 Apr 2024 10:21:00 +0000</pubDate>
      <link>https://forem.com/nikhil6076/angular-at-scale-introduction-to-micro-frontend-architecture-1gh6</link>
      <guid>https://forem.com/nikhil6076/angular-at-scale-introduction-to-micro-frontend-architecture-1gh6</guid>
      <description>&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;In the evolving landscape of web development, the architecture of applications plays a crucial role in ensuring scalability, maintainability, and efficiency. One such architectural pattern that has gained significant traction is the concept of micro frontends. This approach extends the principles of microservices to the frontend, allowing teams to break down a monolithic frontend into smaller, more manageable pieces.&lt;/p&gt;

&lt;h2&gt;
  
  
  What are Micro Frontends?
&lt;/h2&gt;

&lt;p&gt;Micro frontends are essentially segments of a frontend application that encapsulate specific functionalities or features. They can be developed, tested, and deployed independently, offering a modular approach to building complex web applications. This architecture enables multiple teams to work in parallel, each focusing on distinct aspects of the application without stepping on each other’s toes.&lt;/p&gt;

&lt;h3&gt;
  
  
  Benefits of Micro Frontends:
&lt;/h3&gt;

&lt;p&gt;• &lt;strong&gt;Decoupled Codebases&lt;/strong&gt;: Each micro frontend has its own codebase, reducing dependency conflicts and simplifying updates.&lt;br&gt;
• &lt;strong&gt;Autonomous Teams&lt;/strong&gt;: Teams can work independently, choosing their own technology stacks and release cycles.&lt;br&gt;
• &lt;strong&gt;Scalable Development&lt;/strong&gt;: New features can be developed and deployed without the need to understand the entire frontend codebase.&lt;br&gt;
• &lt;strong&gt;Reusable Components&lt;/strong&gt;: Common features can be shared across different parts of the application, promoting reusability.&lt;/p&gt;
&lt;h2&gt;
  
  
  Implementing Micro Frontends with Angular
&lt;/h2&gt;

&lt;p&gt;Angular, with its component-based architecture, is well-suited for implementing micro frontends. Here’s how you can leverage Angular to build a micro frontend architecture:&lt;/p&gt;
&lt;h3&gt;
  
  
  Example: E-Commerce Application
&lt;/h3&gt;

&lt;p&gt;Consider an e-commerce platform composed of several micro frontends such as Product Listing, Shopping Cart, and Checkout.&lt;/p&gt;
&lt;h3&gt;
  
  
  Product Listing Micro Frontend
&lt;/h3&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// product-listing.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-product-listing&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;template&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;`
    &amp;lt;div *ngFor="let product of products"&amp;gt;
      &amp;lt;app-product-item [product]="product"&amp;gt;&amp;lt;/app-product-item&amp;gt;
    &amp;lt;/div&amp;gt;
  `&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;standalone&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="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;ProductListingComponent&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;products&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[...];&lt;/span&gt; &lt;span class="c1"&gt;// Array of product data&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h3&gt;
  
  
  Shopping Cart Micro Frontend
&lt;/h3&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// shopping-cart.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-shopping-cart&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;template&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;`
    &amp;lt;div *ngFor="let item of cartItems"&amp;gt;
      &amp;lt;app-cart-item [item]="item"&amp;gt;&amp;lt;/app-cart-item&amp;gt;
    &amp;lt;/div&amp;gt;
  `&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;standalone&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="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;ShoppingCartComponent&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;cartItems&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[...];&lt;/span&gt; &lt;span class="c1"&gt;// Array of items in the cart&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h2&gt;
  
  
  Integration and Communication
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;Integrating&lt;/code&gt; two micro frontends deployed on separate servers into a single webpage can be achieved using several methods. One popular approach is using &lt;code&gt;Single-SPA&lt;/code&gt;, a JavaScript framework for front-end microservices that allows you to integrate multiple micro frontend applications into one cohesive experience1.&lt;/p&gt;

&lt;p&gt;Here’s a simplified process on how we can achieve this:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Create a Container Application&lt;/strong&gt;: This will act as the main shell that loads and coordinates the micro frontends.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Use Module Federation&lt;/strong&gt;: If you’re using Webpack 5, Module Federation allows you to dynamically load separate micro frontends as if they were part of the same application.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Configure Routes&lt;/strong&gt;: Define routes in your container application that correspond to each micro frontend. When a route is accessed, the corresponding micro frontend is loaded.&lt;/p&gt;

&lt;p&gt;Micro frontends can &lt;code&gt;communicate&lt;/code&gt; with each other through a shared state management system or via custom events. For instance, when a product is added to the cart in the Product Listing, it can emit an event that the Shopping Cart micro frontend listens to and updates its state accordingly.&lt;/p&gt;
&lt;h3&gt;
  
  
  Shared Services
&lt;/h3&gt;

&lt;p&gt;Shared services are a common way to enable communication between micro frontends. These services can be injected into each micro frontend to share data and functionality.&lt;/p&gt;
&lt;h3&gt;
  
  
  Example: Shared Cart Service
&lt;/h3&gt;

&lt;p&gt;Let's consider the e-commerce application that we created earlier. To communicate between those two front ends a &lt;code&gt;CartService&lt;/code&gt; can be used to manage the cart items.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// cart.service.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;Injectable&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;BehaviorSubject&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;rxjs&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;Injectable&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
  &lt;span class="na"&gt;providedIn&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;root&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;CartService&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kr"&gt;private&lt;/span&gt; &lt;span class="nx"&gt;cartItems&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;BehaviorSubject&lt;/span&gt;&lt;span class="p"&gt;([]);&lt;/span&gt;

  &lt;span class="nf"&gt;getCartItems&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;cartItems&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;asObservable&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="nf"&gt;addToCart&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;product&lt;/span&gt;&lt;span class="p"&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;updatedCart&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[...&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;cartItems&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="nx"&gt;product&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;
    &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;cartItems&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;next&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;updatedCart&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;The &lt;code&gt;CartService&lt;/code&gt; uses RxJS’s &lt;code&gt;BehaviorSubject&lt;/code&gt; to maintain a reactive list of cart items. Any micro frontend can inject this service to add items to the cart or subscribe to the cart items stream.&lt;/p&gt;

&lt;h3&gt;
  
  
  Custom Events
&lt;/h3&gt;

&lt;p&gt;Angular applications can also use custom events for communication. This is particularly useful when micro frontends are encapsulated within web components.&lt;/p&gt;

&lt;h3&gt;
  
  
  Example: Custom Event for Product Selection
&lt;/h3&gt;

&lt;p&gt;The product listings micro frontend can emit a custom event when a product is selected, which the shopping cart micro frontend can listen to and respond accordingly.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// product-listings.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="nx"&gt;Output&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;EventEmitter&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-product-listings&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;template&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;`
    &amp;lt;div *ngFor="let product of products"&amp;gt;
      &amp;lt;button (click)="selectProduct(product)"&amp;gt;Add to Cart&amp;lt;/button&amp;gt;
    &amp;lt;/div&amp;gt;
  `&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;standalone&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="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;ProductListingsComponent&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="p"&gt;@&lt;/span&gt;&lt;span class="nd"&gt;Output&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="nx"&gt;productSelected&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;EventEmitter&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

  &lt;span class="nx"&gt;products&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[...];&lt;/span&gt; &lt;span class="c1"&gt;// Array of product data&lt;/span&gt;

  &lt;span class="nf"&gt;selectProduct&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;product&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;productSelected&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;emit&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;product&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;When a product is selected, the &lt;code&gt;productSelected&lt;/code&gt; event is emitted. The shopping cart micro frontend can then listen for this event and update the cart accordingly.&lt;/p&gt;

&lt;h3&gt;
  
  
  State Management Libraries
&lt;/h3&gt;

&lt;p&gt;For more complex scenarios, state management libraries like NgRx or Akita can be used to manage the state across micro frontends.&lt;/p&gt;

&lt;h3&gt;
  
  
  Example: NgRx Store for User Authentication
&lt;/h3&gt;

&lt;p&gt;If user authentication status needs to be shared across micro frontends, an NgRx store can be set up to manage the authentication state.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// auth.reducer.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;createReducer&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;on&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;@ngrx/store&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;login&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;logout&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.actions&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;initialState&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;loggedIn&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;false&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;_authReducer&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;createReducer&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
  &lt;span class="nx"&gt;initialState&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nf"&gt;on&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;login&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;state&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="p"&gt;...&lt;/span&gt;&lt;span class="nx"&gt;state&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;loggedIn&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="nf"&gt;on&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;logout&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;state&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="p"&gt;...&lt;/span&gt;&lt;span class="nx"&gt;state&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;loggedIn&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;false&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;function&lt;/span&gt; &lt;span class="nf"&gt;authReducer&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;state&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;action&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nf"&gt;_authReducer&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;state&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;action&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;The &lt;code&gt;authReducer&lt;/code&gt; manages the login state, and any micro frontend can dispatch actions to log in or log out the user, with the state being reactive and accessible across the application.&lt;/p&gt;

&lt;h2&gt;
  
  
  Use Cases
&lt;/h2&gt;

&lt;p&gt;•&lt;strong&gt;Large Enterprises&lt;/strong&gt;: Micro frontends are ideal for large enterprises where different teams work on different parts of the application.&lt;br&gt;
•&lt;strong&gt;Scalable Startups&lt;/strong&gt;: Startups that anticipate rapid growth can benefit from the scalability offered by micro frontends.&lt;/p&gt;

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

&lt;p&gt;Micro frontend architecture in Angular offers a path towards a more modular and efficient development process and a flexible way to build scalable applications. By embracing this pattern, organizations can foster better collaboration among teams, streamline the development process, and ultimately deliver a more robust and user-friendly application.&lt;/p&gt;

&lt;p&gt;Thank's for your time, see you soon in another one :)&lt;/p&gt;

</description>
      <category>angular</category>
      <category>javascript</category>
      <category>frontend</category>
      <category>webdev</category>
    </item>
    <item>
      <title>Angular + Webpack: An Overview</title>
      <dc:creator>Nikhil Sai</dc:creator>
      <pubDate>Fri, 22 Sep 2023 10:21:12 +0000</pubDate>
      <link>https://forem.com/nikhil6076/angular-webpack-an-overview-44n6</link>
      <guid>https://forem.com/nikhil6076/angular-webpack-an-overview-44n6</guid>
      <description>&lt;p&gt;Webpack is a powerful and versatile tool that plays a crucial role in modern web development, particularly in the context of Angular applications. In this comprehensive article, we'll embark on a deep dive into Webpack, unraveling its inner workings, and understanding its indispensable role in Angular development, from bundling and code optimization to the deployment of applications.&lt;/p&gt;

&lt;h2&gt;
  
  
  What Is Webpack?
&lt;/h2&gt;

&lt;p&gt;Webpack is a JavaScript module bundler. At its core, it takes modules with dependencies and generates static assets representing those modules. While this may sound simple, Webpack's capabilities and features are extensive, making it an essential part of the modern front-end development workflow.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Anatomy of Webpack
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Entry Points
&lt;/h3&gt;

&lt;p&gt;Webpack starts its journey with entry points. An entry point is a file that Webpack uses as the starting point for building your application. In an Angular project, the primary entry point is usually &lt;code&gt;main.ts&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// main.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;platformBrowserDynamic&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-dynamic&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;AppModule&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/app.module&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="nf"&gt;platformBrowserDynamic&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;&lt;span class="nf"&gt;bootstrapModule&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;AppModule&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="k"&gt;catch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;err&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;error&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;err&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here, we import Angular's &lt;code&gt;platformBrowserDynamic&lt;/code&gt; and our &lt;code&gt;AppModule&lt;/code&gt;, initializing our application with &lt;code&gt;platformBrowserDynamic().bootstrapModule(AppModule)&lt;/code&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  Loaders
&lt;/h3&gt;

&lt;p&gt;Loaders in Webpack are used to preprocess files. They transform files before they're added to the dependency graph. Common loaders in Angular projects handle TypeScript (using &lt;code&gt;ts-loader&lt;/code&gt;), CSS (using &lt;code&gt;css-loader&lt;/code&gt;), and HTML (using &lt;code&gt;html-loader&lt;/code&gt;). Loaders make it possible to bundle a wide range of file types in your application.&lt;/p&gt;

&lt;h3&gt;
  
  
  Plugins
&lt;/h3&gt;

&lt;p&gt;While loaders transform files, plugins offer a more extensive range of tasks. They can be used for everything from code splitting and minification to generating HTML files and optimizing assets. The &lt;code&gt;HtmlWebpackPlugin&lt;/code&gt; is a popular plugin in Angular projects, automatically injecting script tags into your HTML.&lt;/p&gt;

&lt;h3&gt;
  
  
  Output
&lt;/h3&gt;

&lt;p&gt;Webpack's &lt;code&gt;output&lt;/code&gt; configuration determines where and how bundles and assets are generated. You can specify output filenames, paths, and various other settings.&lt;/p&gt;

&lt;h2&gt;
  
  
  Bundling and Code Optimization
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Code Bundling
&lt;/h3&gt;

&lt;p&gt;Webpack takes all the modules in your project and bundles them into one or more bundles. This bundling process is crucial for optimizing load times since it reduces the number of requests a browser needs to make to render your application.&lt;/p&gt;

&lt;h3&gt;
  
  
  Tree Shaking
&lt;/h3&gt;

&lt;p&gt;Tree shaking is a feature that eliminates unused code from your bundles. It's particularly important in large applications to ensure that only the code necessary for rendering the current view is loaded.&lt;/p&gt;

&lt;h3&gt;
  
  
  Code Splitting
&lt;/h3&gt;

&lt;p&gt;Webpack supports code splitting, allowing you to split your code into smaller, more manageable pieces. This is advantageous for large applications as it enables lazy loading of modules, reducing the initial load time.&lt;/p&gt;

&lt;h2&gt;
  
  
  Webpack in Angular Development
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Angular CLI and Webpack
&lt;/h3&gt;

&lt;p&gt;Angular CLI, the official command-line tool for Angular, uses Webpack under the hood. When you create a new Angular project using the CLI, it sets up a Webpack configuration tailored for Angular development. This configuration includes loaders, plugins, and optimizations specific to Angular.&lt;/p&gt;

&lt;h3&gt;
  
  
  Ahead-of-Time (AOT) Compilation
&lt;/h3&gt;

&lt;p&gt;Angular's Ahead-of-Time compilation mode plays a significant role in optimizing Angular applications. AOT compiles your Angular templates during the build process, generating highly optimized JavaScript code. Webpack supports AOT compilation in Angular projects, ensuring that the resulting bundles are as efficient as possible.&lt;/p&gt;

&lt;h2&gt;
  
  
  Deep Dive: How Webpack Bundles Angular
&lt;/h2&gt;

&lt;p&gt;Webpack's role in bundling an Angular application involves handling all the assets and dependencies of your project, from TypeScript files and HTML templates to styles and images. Let's explore a simplified overview of this process:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Entry Point&lt;/strong&gt;: Webpack starts at the entry point, typically &lt;code&gt;main.ts&lt;/code&gt;, and begins building the dependency graph.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Loaders&lt;/strong&gt;: Loaders preprocess files as they're imported. For instance, TypeScript files are transpiled into JavaScript.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Dependency Resolution&lt;/strong&gt;: Webpack resolves dependencies, tracking which modules depend on others.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Bundling&lt;/strong&gt;: Webpack bundles all modules into one or more output files. It employs various optimizations like minification, dead code elimination, and mangling to generate efficient bundles.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Code Splitting&lt;/strong&gt;: Code splitting is used to create smaller bundles for lazy-loaded modules, optimizing initial load times.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Tree Shaking&lt;/strong&gt;: Unused code is eliminated from the bundles, reducing the overall bundle size.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Output&lt;/strong&gt;: The final bundles and assets are generated according to the specified &lt;code&gt;output&lt;/code&gt; configuration.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

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

&lt;p&gt;Webpack is a foundational tool in Angular development, responsible for bundling, optimizing, and managing all the assets in your application. Its intricate configuration, loaders, plugins, and optimization techniques are vital for delivering efficient, high-performance Angular applications to users.&lt;/p&gt;

&lt;p&gt;Thank's for your time, see you soon in another one :)&lt;/p&gt;

</description>
      <category>angular</category>
      <category>javascript</category>
      <category>webdev</category>
      <category>frontend</category>
    </item>
    <item>
      <title>Angular Signals : A Comprehensive Introduction</title>
      <dc:creator>Nikhil Sai</dc:creator>
      <pubDate>Wed, 20 Sep 2023 12:40:12 +0000</pubDate>
      <link>https://forem.com/nikhil6076/angular-signals-a-comprehensive-introduction-45h2</link>
      <guid>https://forem.com/nikhil6076/angular-signals-a-comprehensive-introduction-45h2</guid>
      <description>&lt;p&gt;Angular as we know is a popular framework for building web applications that are dynamic, interactive, and responsive. One of the key aspects of Angular is its change detection mechanism, which is responsible for updating the view whenever the data changes. Angular uses a zone-based approach to detect changes, which means that it runs a change detection cycle whenever an event occurs, such as a user input, a timer, an HTTP request, etc.&lt;/p&gt;

&lt;p&gt;However, this approach has some drawbacks, such as:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;It can be inefficient, as it may run change detection for the entire application even if only a small part of it has changed.&lt;/li&gt;
&lt;li&gt;It can be inconsistent, as some events may not trigger change detection automatically, such as web sockets or third-party libraries.&lt;/li&gt;
&lt;li&gt;To address these issues, Angular introduces a new feature called signals, which is a new reactive primitive type that can notify interested consumers when its value changes. Signals can contain any value, from simple primitives to complex data structures. A signal’s value is always read through a getter function, which allows Angular to track where the signal is used.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Signals can be either writable or read-only. Writable signals provide an API for updating their values directly or indirectly. Read-only signals derive their values from other signals using a derivation function.&lt;/p&gt;

&lt;p&gt;Signals provide several benefits, such as:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;They are more efficient, as they only update the parts of the application that depend on them.&lt;/li&gt;
&lt;li&gt;They are simpler, as they use a declarative syntax that is easy to read and write.&lt;/li&gt;
&lt;li&gt;They are more consistent, as they react to any changes in their dependencies automatically.&lt;/li&gt;
&lt;li&gt;In this article, we will explore how to use signals in Angular and see some examples of how they can improve our code. We will also learn about two other features of signals: compute and effect. Compute is a way to create computed values that depend on signals. Effect is a way to create side effects that run when signals change.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Creating Signals
&lt;/h2&gt;

&lt;p&gt;To create a writable signal, we can use the signal function and pass the initial value of the signal as an argument. For example:&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="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;count&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;signal&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="c1"&gt;// Creates a writable signal with an initial value of 0&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To read the value of a signal, we can simply call it as a getter function. For example:&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="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;count&lt;/span&gt;&lt;span class="p"&gt;());&lt;/span&gt; &lt;span class="c1"&gt;// Logs 0&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To update the value of a writable signal, we can use the set method and pass the new value as an argument. For example:&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="nx"&gt;count&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;set&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="c1"&gt;// Sets the value of count to 1&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;count&lt;/span&gt;&lt;span class="p"&gt;());&lt;/span&gt; &lt;span class="c1"&gt;// Logs 1&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We can also use the update method to compute a new value from the previous one using a callback function. For example:&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="nx"&gt;count&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;update&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;value&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;value&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// Increments the value of count by 1&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;count&lt;/span&gt;&lt;span class="p"&gt;());&lt;/span&gt; &lt;span class="c1"&gt;// Logs 2&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To create a read-only signal, we can use the computed function and pass a derivation function that returns the value of the signal based on other signals. For example:&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="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;doubleCount&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;computed&lt;/span&gt;&lt;span class="p"&gt;(()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nf"&gt;count&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// Creates a read-only signal that depends on count&lt;/span&gt;

&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;doubleCount&lt;/span&gt;&lt;span class="p"&gt;());&lt;/span&gt; &lt;span class="c1"&gt;// Logs 4&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The derivation function of a computed signal is lazily evaluated and memoized, which means that it only runs when the signal is first read or when any of its dependencies change. The result of the derivation function is cached and returned for subsequent reads until it becomes invalid.&lt;/p&gt;

&lt;h3&gt;
  
  
  Using Signals in Templates
&lt;/h3&gt;

&lt;p&gt;One of the main use cases of signals is to bind them in templates and let Angular’s change detection update the view automatically whenever the signals change. To do this, we need to use signals in our components and expose them as public properties.&lt;/p&gt;

&lt;p&gt;For example, let’s say we have a simple component that displays a counter and allows us to increment or decrement it using buttons. We can use signals to implement this component as follows:&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;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="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;signal&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/signals&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-counter&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;template&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;`
    &amp;lt;div&amp;gt;
      &amp;lt;button (click)="decrement()"&amp;gt;-&amp;lt;/button&amp;gt;
      &amp;lt;span&amp;gt;{{ count() }}&amp;lt;/span&amp;gt;
      &amp;lt;button (click)="increment()"&amp;gt;+&amp;lt;/button&amp;gt;
    &amp;lt;/div&amp;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;CounterComponent&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="c1"&gt;// Creates a writable signal with an initial value of 0&lt;/span&gt;
  &lt;span class="nx"&gt;count&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;signal&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="c1"&gt;// Increments the count by 1&lt;/span&gt;
  &lt;span class="nf"&gt;increment&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;count&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;update&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;value&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;value&lt;/span&gt; &lt;span class="o"&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="c1"&gt;// Decrements the count by 1&lt;/span&gt;
  &lt;span class="nf"&gt;decrement&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;count&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;update&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;value&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;value&lt;/span&gt; &lt;span class="o"&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;p&gt;In the template, we can use the count signal as a normal property and interpolate it using the &lt;code&gt;{{ }}&lt;/code&gt; syntax. We can also call the increment and decrement methods on the component instance using the &lt;code&gt;(click)&lt;/code&gt; event binding.&lt;/p&gt;

&lt;p&gt;When we run this component, we can see that the view reflects the value of the count signal and updates whenever we click on the buttons. This is because Angular tracks the count signal as a dependency of the component and marks it for change detection whenever it changes.&lt;/p&gt;

&lt;p&gt;We can also use signals in other template expressions, such as property bindings, attribute bindings, class bindings, style bindings, etc. For example, we can use a computed signal to disable the decrement button when the count is zero:&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;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="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;signal&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;computed&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/signals&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-counter&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;template&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;`
    &amp;lt;div&amp;gt;
      &amp;lt;button (click)="decrement()" [disabled]="isZero()"&amp;gt;-&amp;lt;/button&amp;gt;
      &amp;lt;span&amp;gt;{{ count() }}&amp;lt;/span&amp;gt;
      &amp;lt;button (click)="increment()"&amp;gt;+&amp;lt;/button&amp;gt;
    &amp;lt;/div&amp;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;CounterComponent&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="c1"&gt;// Creates a writable signal with an initial value of 0&lt;/span&gt;
  &lt;span class="nx"&gt;count&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;signal&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="c1"&gt;// Creates a read-only signal that depends on count&lt;/span&gt;
  &lt;span class="nx"&gt;isZero&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;computed&lt;/span&gt;&lt;span class="p"&gt;(()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;count&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

  &lt;span class="c1"&gt;// Increments the count by 1&lt;/span&gt;
  &lt;span class="nf"&gt;increment&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;count&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;update&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;value&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;value&lt;/span&gt; &lt;span class="o"&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="c1"&gt;// Decrements the count by 1&lt;/span&gt;
  &lt;span class="nf"&gt;decrement&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;count&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;update&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;value&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;value&lt;/span&gt; &lt;span class="o"&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;p&gt;In this case, we use the &lt;code&gt;[disabled]&lt;/code&gt; property binding to bind the &lt;code&gt;isZero&lt;/code&gt; signal to the disabled attribute of the button element. The &lt;code&gt;isZero&lt;/code&gt; signal is a computed signal that returns true if the count signal is equal to zero, and false otherwise.&lt;/p&gt;

&lt;p&gt;When we run this component, we can see that the decrement button is disabled when the count is zero and enabled otherwise. This is because Angular tracks the isZero signal as a dependency of the component and updates its view whenever it changes.&lt;/p&gt;

&lt;h3&gt;
  
  
  Compute and Effect
&lt;/h3&gt;

&lt;p&gt;Another feature of signals is that they can be used to create computed values and effects. Computed values are signals that derive their values from other signals using a derivation function. Effects are operations that run whenever one or more signals change. Effects do not return any value, but they can perform side effects such as logging, updating local storage, calling APIs, etc.&lt;/p&gt;

&lt;p&gt;To create a computed value, we can use the computed function and pass a derivation function that returns the value of the signal based on other signals. For example:&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="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;signal&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Alice&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// Creates a writable signal with an initial string value&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;greeting&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;computed&lt;/span&gt;&lt;span class="p"&gt;(()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Hello, &lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nf"&gt;name&lt;/span&gt;&lt;span class="p"&gt;());&lt;/span&gt; &lt;span class="c1"&gt;// Creates a read-only signal that depends on name&lt;/span&gt;

&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;greeting&lt;/span&gt;&lt;span class="p"&gt;());&lt;/span&gt; &lt;span class="c1"&gt;// Logs 'Hello, Alice'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The derivation function of a computed value is similar to that of a computed signal, except that it does not need to wrap its return value in a getter function. The computed value will automatically update whenever any of its dependencies change.&lt;/p&gt;

&lt;p&gt;To create an effect, we can use the effect function and pass an effect function that performs some operation based on one or more signals. For example:&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="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;signal&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Alice&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// Creates a writable signal with an initial string value&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;greeting&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;computed&lt;/span&gt;&lt;span class="p"&gt;(()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Hello, &lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nf"&gt;name&lt;/span&gt;&lt;span class="p"&gt;());&lt;/span&gt; &lt;span class="c1"&gt;// Creates a read-only signal that depends on name&lt;/span&gt;

&lt;span class="nf"&gt;effect&lt;/span&gt;&lt;span class="p"&gt;(()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;greeting&lt;/span&gt;&lt;span class="p"&gt;()));&lt;/span&gt; &lt;span class="c1"&gt;// Creates an effect that logs greeting&lt;/span&gt;

&lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;set&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Bob&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// Updates name to 'Bob'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The effect function of an effect is similar to that of a computed value, except that it does not return any value. The effect will automatically run whenever any of its dependencies change. The effect will also run at least once when it is created.&lt;/p&gt;

&lt;p&gt;We can use compute and effect to create various kinds of reactive logic in our applications. For example, we can use compute to create a filtered list of todos based on a search query:&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="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;todos&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;signal&lt;/span&gt;&lt;span class="p"&gt;([&lt;/span&gt;
  &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;title&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Learn signals&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;done&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;title&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Write an article&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;done&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt; &lt;span class="p"&gt;},&lt;/span&gt;
  &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;title&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Read a book&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;done&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt; &lt;span class="p"&gt;},&lt;/span&gt;
&lt;span class="p"&gt;]);&lt;/span&gt; &lt;span class="c1"&gt;// Creates a writable signal with an initial array value&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;query&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;signal&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="c1"&gt;// Creates a writable signal with an initial string value&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;filteredTodos&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;computed&lt;/span&gt;&lt;span class="p"&gt;(()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="c1"&gt;// Creates a read-only signal that depends on todos and query&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nf"&gt;todos&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;&lt;span class="nf"&gt;filter&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;todo&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt;
    &lt;span class="nx"&gt;todo&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;title&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;toLowerCase&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;&lt;span class="nf"&gt;includes&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;query&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;&lt;span class="nf"&gt;toLowerCase&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;In this case, we use the todos signal to store the list of todos and the query signal to store the search query. We use the filteredTodos signal to derive a new list of todos that match the query using the filter method. The filteredTodos signal will update whenever the todos or the query signals change.&lt;/p&gt;

&lt;p&gt;We can use effect to create a local storage sync for our todos:&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="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;todos&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;signal&lt;/span&gt;&lt;span class="p"&gt;([&lt;/span&gt;
  &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;title&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Learn signals&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;done&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;title&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Write an article&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;done&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt; &lt;span class="p"&gt;},&lt;/span&gt;
  &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;title&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Read a book&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;done&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt; &lt;span class="p"&gt;},&lt;/span&gt;
&lt;span class="p"&gt;]);&lt;/span&gt; &lt;span class="c1"&gt;// Creates a writable signal with an initial array value&lt;/span&gt;

&lt;span class="nf"&gt;effect&lt;/span&gt;&lt;span class="p"&gt;(()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="c1"&gt;// Creates an effect that depends on todos&lt;/span&gt;
  &lt;span class="nx"&gt;localStorage&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;setItem&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;todos&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;JSON&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;stringify&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;todos&lt;/span&gt;&lt;span class="p"&gt;()));&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt; &lt;span class="c1"&gt;// Syncs the todos to local storage whenever they change&lt;/span&gt;

&lt;span class="nf"&gt;effect&lt;/span&gt;&lt;span class="p"&gt;(()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="c1"&gt;// Creates an effect that runs once&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;storedTodos&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;localStorage&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getItem&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;todos&lt;/span&gt;&lt;span class="dl"&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;storedTodos&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;todos&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;set&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;JSON&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;parse&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;storedTodos&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="c1"&gt;// Loads the todos from local storage when the app starts&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this case, we use the first effect to sync the todos signal to local storage using the setItem method. The effect will run whenever the todos signal changes. We use the second effect to load the todos signal from local storage using the getItem method. The effect will run only once when the app starts.&lt;/p&gt;

&lt;h3&gt;
  
  
  Conclusion
&lt;/h3&gt;

&lt;p&gt;In this article, we have learned about signals, a new feature in Angular that allows us to write reactive code using a simple and declarative syntax. We have seen how to create and use signals in our components and templates, how to create computed values and effects with signals.&lt;/p&gt;

&lt;p&gt;Signals are a powerful and expressive way to manage data flow and state changes in our applications. They can help us write code that is more efficient, simpler, and consistent. They can also enable us to create more dynamic, interactive, and responsive user interfaces.&lt;/p&gt;

&lt;p&gt;Thank's for your time, see you soon in another one :)&lt;/p&gt;

</description>
      <category>angular</category>
      <category>beginners</category>
      <category>webdev</category>
      <category>javascript</category>
    </item>
    <item>
      <title>10 Common Mistakes to Avoid While Building An Efficient Angular Application</title>
      <dc:creator>Nikhil Sai</dc:creator>
      <pubDate>Mon, 11 Sep 2023 10:53:37 +0000</pubDate>
      <link>https://forem.com/nikhil6076/10-common-mistakes-to-avoid-while-building-an-efficient-angular-application-4nhj</link>
      <guid>https://forem.com/nikhil6076/10-common-mistakes-to-avoid-while-building-an-efficient-angular-application-4nhj</guid>
      <description>&lt;p&gt;Developing an efficient Angular website can be a rewarding experience, but it's easy to stumble into these common mistakes. In this article, we'll explore some of these mistakes and provide clear explanations and examples to help you avoid them.&lt;/p&gt;

&lt;h2&gt;
  
  
  1: Neglecting Module Organization
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Explanation:&lt;/strong&gt; Angular encourages the use of modules to organize your application. Neglecting this can lead to a disorganized and hard-to-maintain codebase.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Example:&lt;/strong&gt; Let's say you have a shopping website. Instead of creating separate modules for features like product listing, cart, and user authentication, you put everything in a single module. This can lead to a tangled mess of code.&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;// All components and services in one app module&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;ProductListComponent&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;CartComponent&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="c1"&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;&lt;strong&gt;Solution:&lt;/strong&gt; Organize your application into feature modules. Create a &lt;code&gt;ProductModule&lt;/code&gt;, &lt;code&gt;CartModule&lt;/code&gt;, and &lt;code&gt;AuthModule&lt;/code&gt;, each containing their respective components and services.&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;// Organized feature modules&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;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;ProductModule&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;CartModule&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;AuthModule&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;
  &lt;span class="c1"&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;h2&gt;
  
  
  2: Ignoring Lazy Loading
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Explanation:&lt;/strong&gt; Failing to implement lazy loading can result in larger initial load times and decreased performance.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Example:&lt;/strong&gt; Imagine all modules are eagerly loaded in your application. When a user accesses the homepage, every feature module is loaded, including those they might not use immediately.&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;// Eagerly loading modules&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;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;ProductModule&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;CartModule&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;AuthModule&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;
  &lt;span class="c1"&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;&lt;strong&gt;Solution:&lt;/strong&gt; Utilize lazy loading to load modules only when they are needed. This improves the initial load time.&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="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="s1"&gt;products&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;loadChildren&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="k"&gt;import&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;./product/product.module&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;then&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;m&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;m&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;ProductModule&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;path&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;cart&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;loadChildren&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="k"&gt;import&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;./cart/cart.module&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;then&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;m&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;m&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;CartModule&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;path&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;auth&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;loadChildren&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="k"&gt;import&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;./auth/auth.module&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;then&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;m&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;m&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;AuthModule&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;h2&gt;
  
  
  3: Overusing ngIf and ngFor
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Explanation:&lt;/strong&gt; Excessive use of structural directives like &lt;code&gt;*ngIf&lt;/code&gt; and &lt;code&gt;*ngFor&lt;/code&gt; can lead to performance issues.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Example:&lt;/strong&gt; Consider a list of products. If you use &lt;code&gt;*ngIf&lt;/code&gt; to display each product individually, Angular will create and destroy DOM elements for each product, causing unnecessary overhead.&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="c"&gt;&amp;lt;!-- Using *ngIf for each product --&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;*ngFor=&lt;/span&gt;&lt;span class="s"&gt;"let product of products"&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;*ngIf=&lt;/span&gt;&lt;span class="s"&gt;"product.isVisible"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;{{ product.name }}&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;&lt;strong&gt;Solution:&lt;/strong&gt; Instead of using &lt;code&gt;*ngIf&lt;/code&gt; for each item, filter your data in the component to exclude hidden items before rendering.&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="c"&gt;&amp;lt;!-- Filtering data in component --&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;*ngFor=&lt;/span&gt;&lt;span class="s"&gt;"let product of visibleProducts"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
  {{ product.name }}
&lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  4: Neglecting Data Prefetching
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Explanation:&lt;/strong&gt; An alternative mistake regarding data retrieval is neglecting to prefetch data when it's likely to be needed in the near future. But be careful and observe the difference between data prefetching and lazy loading.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Example:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Suppose your e-commerce site doesn't prefetch product details when a user hovers over a product card. Instead, it makes an HTTP request only when the user clicks on a product.&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;// ProductComponent.ts&lt;/span&gt;
&lt;span class="nf"&gt;onProductClick&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;productId&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;string&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;http&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;`/api/products/&lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;productId&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;subscribe&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;productData&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;data&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;&lt;strong&gt;Solution:&lt;/strong&gt; Prefetch data proactively to enhance user experience.&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;// Better Approach: Prefetch product data on hover&lt;/span&gt;
&lt;span class="c1"&gt;// ProductComponent.ts&lt;/span&gt;
&lt;span class="nf"&gt;onProductHover&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;productId&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;string&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;http&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;`/api/products/&lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;productId&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;subscribe&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;preloadedData&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;});&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nf"&gt;onProductClick&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;productData&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;preloadedData&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;h2&gt;
  
  
  5: Not Handling Error Responses
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Explanation:&lt;/strong&gt; Failing to handle error responses properly can lead to a poor user experience and leave your application vulnerable.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Example:&lt;/strong&gt; You make an HTTP request, but you don't handle errors, so if the server returns an error status, the application crashes.&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;// Not handling HTTP errors&lt;/span&gt;
&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;http&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;/api/products&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;subscribe&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
  &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;// Handle successful response&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;&lt;strong&gt;Solution:&lt;/strong&gt; Always include error handling to gracefully manage HTTP errors and provide feedback to users.&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;// Handling HTTP errors&lt;/span&gt;
&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;http&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;/api/products&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;subscribe&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
  &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;// Handle successful response&lt;/span&gt;
  &lt;span class="p"&gt;},&lt;/span&gt;
  &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;error&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;// Handle errors, e.g., show an error message&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&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;HTTP Error:&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;error&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;h2&gt;
  
  
  6: Not Implementing Routing Guards
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Explanation:&lt;/strong&gt; Neglecting to use Angular routing guards can lead to unauthorized access or navigation issues in your application.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Example:&lt;/strong&gt; You have a route that should be accessible only to authenticated users, but you don't implement a route guard, allowing anyone to access it.&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="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="s1"&gt;dashboard&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;DashboardComponent&lt;/span&gt; &lt;span class="p"&gt;},&lt;/span&gt;
  &lt;span class="c1"&gt;// ...&lt;/span&gt;
&lt;span class="p"&gt;];&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Solution:&lt;/strong&gt; Implement route guards to control access to routes and protect sensitive parts of your application.&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;// Implementing an authentication guard&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="s1"&gt;dashboard&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;DashboardComponent&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;canActivate&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;AuthGuard&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="p"&gt;},&lt;/span&gt;
  &lt;span class="c1"&gt;// ...&lt;/span&gt;
&lt;span class="p"&gt;];&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  7: Not Utilizing OnPush Change Detection
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Explanation:&lt;/strong&gt; Neglecting the OnPush change detection strategy can lead to inefficient rendering and decreased performance in your Angular components.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Example:&lt;/strong&gt; You have a component that doesn't utilize the OnPush strategy, causing unnecessary re-renders even when the input properties haven't changed.&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="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-product&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;./product.component.html&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="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;ProductComponent&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="p"&gt;@&lt;/span&gt;&lt;span class="nd"&gt;Input&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="nx"&gt;product&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;Product&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="c1"&gt;// ...&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Solution:&lt;/strong&gt; Enable the OnPush change detection strategy to optimize component rendering.&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;// Using OnPush change detection strategy&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-product&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;./product.component.html&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;changeDetection&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;ChangeDetectionStrategy&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;OnPush&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;ProductComponent&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="p"&gt;@&lt;/span&gt;&lt;span class="nd"&gt;Input&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="nx"&gt;product&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;Product&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="c1"&gt;// ...&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  8: Overusing ng-container
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Explanation:&lt;/strong&gt; Using too many &lt;code&gt;ng-container&lt;/code&gt; elements can make your templates complex and harder to understand.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Example:&lt;/strong&gt; You have nested &lt;code&gt;ng-container&lt;/code&gt; elements to conditionally render content, making the template difficult to read.&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;ng-container&lt;/span&gt; &lt;span class="na"&gt;*ngIf=&lt;/span&gt;&lt;span class="s"&gt;"condition"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;ng-container&lt;/span&gt; &lt;span class="na"&gt;*ngIf=&lt;/span&gt;&lt;span class="s"&gt;"anotherCondition"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="c"&gt;&amp;lt;!-- Content --&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;/ng-container&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/ng-container&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Solution:&lt;/strong&gt; Simplify your templates by using regular HTML elements when possible.&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="c"&gt;&amp;lt;!-- Simplified template --&amp;gt;&lt;/span&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;"condition"&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;*ngIf=&lt;/span&gt;&lt;span class="s"&gt;"anotherCondition"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="c"&gt;&amp;lt;!-- Content --&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;h2&gt;
  
  
  9: Not Optimizing for Mobile
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Explanation:&lt;/strong&gt; Failing to optimize your Angular website for mobile devices can result in a poor user experience on smartphones and tablets, so make sure you make your website responsive.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Example:&lt;/strong&gt; Your website layout and design don't adapt well to smaller screens, making it challenging for mobile users to navigate.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nc"&gt;.container&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;width&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;1200px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="c"&gt;/* ... */&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Solution:&lt;/strong&gt; Implement responsive design techniques using CSS media queries to ensure your website looks and functions well on various screen sizes. Avoid mentioning the sizes in absolute units (ex: in, px) and use relative units (ex: em, rem, %) where ever possible.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;
&lt;span class="nc"&gt;.container&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;max-width&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;100%&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="c"&gt;/* ... */&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  10: Ignoring SEO Best Practices
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Explanation:&lt;/strong&gt; Neglecting search engine optimization (SEO) best practices can result in poor search engine rankings and reduced discoverability.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Example:&lt;/strong&gt; Your Angular app doesn't have proper meta tags, semantic HTML, or server-side rendering, making it less SEO-friendly.&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="cp"&gt;&amp;lt;!DOCTYPE html&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;html&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;head&amp;gt;&lt;/span&gt;
  &lt;span class="c"&gt;&amp;lt;!-- Missing meta tags and SEO-related elements --&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/head&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;body&amp;gt;&lt;/span&gt;
  &lt;span class="c"&gt;&amp;lt;!-- Angular app content --&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/body&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/html&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Solution:&lt;/strong&gt; Implement SEO best practices by adding meta tags, using semantic HTML elements, and considering server-side rendering (e.g., Angular Universal) for improved SEO.&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="c"&gt;&amp;lt;!-- Correct: SEO-optimized HTML --&amp;gt;&lt;/span&gt;
&lt;span class="cp"&gt;&amp;lt;!DOCTYPE html&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;html&lt;/span&gt; &lt;span class="na"&gt;lang=&lt;/span&gt;&lt;span class="s"&gt;"en"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;head&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;meta&lt;/span&gt; &lt;span class="na"&gt;charset=&lt;/span&gt;&lt;span class="s"&gt;"UTF-8"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;meta&lt;/span&gt; &lt;span class="na"&gt;name=&lt;/span&gt;&lt;span class="s"&gt;"viewport"&lt;/span&gt; &lt;span class="na"&gt;content=&lt;/span&gt;&lt;span class="s"&gt;"width=device-width, initial-scale=1.0"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;title&amp;gt;&lt;/span&gt;Your Page Title&lt;span class="nt"&gt;&amp;lt;/title&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;meta&lt;/span&gt; &lt;span class="na"&gt;name=&lt;/span&gt;&lt;span class="s"&gt;"description"&lt;/span&gt; &lt;span class="na"&gt;content=&lt;/span&gt;&lt;span class="s"&gt;"Your page description"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="c"&gt;&amp;lt;!-- Other SEO-related meta tags --&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/head&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;body&amp;gt;&lt;/span&gt;
  &lt;span class="c"&gt;&amp;lt;!-- Angular app content --&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/body&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/html&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;By addressing the above common things related to change detection, template complexity, responsive design, and SEO, you can create more efficient, user-friendly, and discoverable Angular websites.&lt;/p&gt;

&lt;p&gt;Thank's for your time, see you soon in another one :)&lt;/p&gt;

</description>
      <category>angular</category>
      <category>beginners</category>
      <category>ui</category>
      <category>webdev</category>
    </item>
    <item>
      <title>Create Custom Form Control in Angular</title>
      <dc:creator>Nikhil Sai</dc:creator>
      <pubDate>Wed, 06 Sep 2023 14:20:49 +0000</pubDate>
      <link>https://forem.com/nikhil6076/creating-custom-poll-form-control-in-angular-1da8</link>
      <guid>https://forem.com/nikhil6076/creating-custom-poll-form-control-in-angular-1da8</guid>
      <description>&lt;p&gt;Angular provides a powerful way to create custom form controls to enhance the functionality and reusability of your application. In this article, we'll walk through the process of creating a custom form control step by step, with a detailed explanation, background on &lt;code&gt;NG_VALUE_ACCESSOR&lt;/code&gt;, and a practical example.&lt;/p&gt;

&lt;h2&gt;
  
  
  Background on NG_VALUE_ACCESSOR
&lt;/h2&gt;

&lt;p&gt;In Angular, &lt;code&gt;NG_VALUE_ACCESSOR&lt;/code&gt; is a special injection token used to register and provide a way for Angular forms to communicate with custom form controls. It's a crucial part of creating custom form controls because it allows Angular to integrate them seamlessly into the reactive forms framework.&lt;/p&gt;

&lt;p&gt;When you define a custom form control that implements the &lt;code&gt;ControlValueAccessor&lt;/code&gt; interface and provide it using &lt;code&gt;NG_VALUE_ACCESSOR&lt;/code&gt;, you're essentially telling Angular how to interact with your custom control. This includes syncing values, handling changes, and setting up two-way data binding.&lt;/p&gt;

&lt;h2&gt;
  
  
  ControlValueAccessor Methods
&lt;/h2&gt;

&lt;p&gt;The &lt;code&gt;ControlValueAccessor&lt;/code&gt; interface defines several methods that you must implement in your custom form control class. These methods enable the interaction between your custom control and Angular forms:&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="kr"&gt;interface&lt;/span&gt; &lt;span class="nx"&gt;ControlValueAccessor&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;T&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nf"&gt;writeValue&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="na"&gt;obj&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;T&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt; &lt;span class="k"&gt;void&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nf"&gt;registerOnChange&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="na"&gt;fn&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="na"&gt;value&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;T&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="k"&gt;void&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt; &lt;span class="k"&gt;void&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nf"&gt;registerOnTouched&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="na"&gt;fn&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="k"&gt;void&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt; &lt;span class="k"&gt;void&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nx"&gt;setDisabledState&lt;/span&gt;&lt;span class="p"&gt;?(&lt;/span&gt;&lt;span class="nx"&gt;isDisabled&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;boolean&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt; &lt;span class="k"&gt;void&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;writeValue(value: any)&lt;/code&gt;: This method is used to write a value from the model into the view. It's called when you programmatically set the value of your custom form control. Inside this method, you typically update the internal state of your control.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;registerOnChange(fn: any)&lt;/code&gt;: This method registers a callback function that Angular calls whenever the value of your custom control changes. You should store this callback and call it when your control's value changes to notify Angular.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;registerOnTouched(fn: any)&lt;/code&gt;: This method is similar to &lt;code&gt;registerOnChange&lt;/code&gt;, but it's used to register a callback function that Angular calls when the custom control is "touched" or loses focus. It's typically used to mark the control as touched and trigger validation.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;setDisabledState(isDisabled: boolean)&lt;/code&gt;: This optional method allows you to set the disabled state of your custom control. It's useful when you want to enable or disable the control programmatically.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Now we will see how we can create a Poll form control using the concept we have learnt.&lt;/p&gt;

&lt;h2&gt;
  
  
  Detailed Steps to Create a Custom Poll Control
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Prerequisites&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Before we dive into creating custom form controls, make sure you have the following prerequisites installed:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Node.js and npm (Node Package Manager)&lt;/li&gt;
&lt;li&gt;Angular CLI (Command Line Interface) - You can install it globally using &lt;code&gt;npm install -g @angular/cli&lt;/code&gt;.&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  Step 1: Set Up the Angular Project
&lt;/h3&gt;

&lt;p&gt;If you haven't already, create a new Angular project using the Angular CLI:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;ng new custom-poll-control-example
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Navigate to the project directory:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;cd &lt;/span&gt;custom-poll-control-example
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Step 2: Create a Custom Poll Control
&lt;/h3&gt;

&lt;p&gt;Now, create a custom poll control component using the Angular CLI:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;ng generate component poll-control
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Step 3: Implement the Custom Poll Control with Value Accessor Methods
&lt;/h3&gt;

&lt;p&gt;In the &lt;code&gt;poll-control&lt;/code&gt; component, open the &lt;code&gt;poll-control.component.ts&lt;/code&gt; file, and define the custom form control with value accessor methods:&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;Component&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;forwardRef&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;Input&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;OnInit&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;ControlValueAccessor&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;NG_VALUE_ACCESSOR&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;@angular/forms&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-poll-control&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;./poll-control.component.html&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;styleUrls&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;./poll-control.component.css&lt;/span&gt;&lt;span class="dl"&gt;'&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;NG_VALUE_ACCESSOR&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="na"&gt;useExisting&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nf"&gt;forwardRef&lt;/span&gt;&lt;span class="p"&gt;(()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;PollControlComponent&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="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;PollControlComponent&lt;/span&gt; &lt;span class="k"&gt;implements&lt;/span&gt; &lt;span class="nx"&gt;ControlValueAccessor&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;OnInit&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="p"&gt;@&lt;/span&gt;&lt;span class="nd"&gt;Input&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="nx"&gt;pollOptions&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="c1"&gt;// Input property to receive poll options&lt;/span&gt;
  &lt;span class="nl"&gt;selectedOptions&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="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[];&lt;/span&gt;
  &lt;span class="nl"&gt;onChange&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;any&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{};&lt;/span&gt;
  &lt;span class="nl"&gt;onTouched&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;any&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&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="nf"&gt;ngOnInit&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{}&lt;/span&gt;

  &lt;span class="nf"&gt;writeValue&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="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;selectedOptions&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="p"&gt;}&lt;/span&gt;

  &lt;span class="nf"&gt;registerOnChange&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;fn&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;any&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;onChange&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;fn&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="nf"&gt;registerOnTouched&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;fn&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;any&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;onTouched&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;fn&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="nf"&gt;setDisabledState&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;isDisabled&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;boolean&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;// Implement if needed&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="nf"&gt;updateSelectedOptions&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;option&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;string&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;isSelected&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;option&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;selectedOptions&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;selectedOptions&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;filter&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;item&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;item&lt;/span&gt; &lt;span class="o"&gt;!==&lt;/span&gt; &lt;span class="nx"&gt;option&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;selectedOptions&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;push&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;option&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;onChange&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;selectedOptions&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;onTouched&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="nf"&gt;isSelected&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;option&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;string&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;selectedOptions&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;includes&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;option&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;In this code, we implement the &lt;code&gt;ControlValueAccessor&lt;/code&gt; interface with methods like &lt;code&gt;writeValue&lt;/code&gt;, &lt;code&gt;registerOnChange&lt;/code&gt;, and &lt;code&gt;registerOnTouched&lt;/code&gt;. We also create a method &lt;code&gt;updateSelectedOptions&lt;/code&gt; to handle checkbox changes and update the form control value.&lt;/p&gt;

&lt;h3&gt;
  
  
  Step 4: Create the Custom Poll Control Template
&lt;/h3&gt;

&lt;p&gt;In the &lt;code&gt;poll-control&lt;/code&gt; component directory, open the &lt;code&gt;poll-control.component.html&lt;/code&gt; file, and create the HTML template for the poll control:&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&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;*ngFor=&lt;/span&gt;&lt;span class="s"&gt;"let option of pollOptions"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;label&amp;gt;&lt;/span&gt;
      &lt;span class="nt"&gt;&amp;lt;input&lt;/span&gt;
        &lt;span class="na"&gt;type=&lt;/span&gt;&lt;span class="s"&gt;"checkbox"&lt;/span&gt;
        &lt;span class="na"&gt;[checked]=&lt;/span&gt;&lt;span class="s"&gt;"isSelected(option)"&lt;/span&gt;
        &lt;span class="na"&gt;(change)=&lt;/span&gt;&lt;span class="s"&gt;"updateSelectedOptions(option)"&lt;/span&gt;
      &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
      {{ option }}
    &lt;span class="nt"&gt;&amp;lt;/label&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;h3&gt;
  
  
  Step 5: Using the Custom Poll Control
&lt;/h3&gt;

&lt;p&gt;In a parent component (e.g., &lt;code&gt;app.component.html&lt;/code&gt;), use the custom poll control to create and display a poll:&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;form&lt;/span&gt; &lt;span class="na"&gt;[formGroup]=&lt;/span&gt;&lt;span class="s"&gt;"pollForm"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;app-poll-control&lt;/span&gt; &lt;span class="na"&gt;[pollOptions]=&lt;/span&gt;&lt;span class="s"&gt;"options"&lt;/span&gt; &lt;span class="na"&gt;formControlName=&lt;/span&gt;&lt;span class="s"&gt;"pollOptions"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&amp;lt;/app-poll-control&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;"submitPoll()"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Submit Poll&lt;span class="nt"&gt;&amp;lt;/button&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/form&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Step 6: Handling the Poll Data
&lt;/h3&gt;

&lt;p&gt;In your parent component (e.g., &lt;code&gt;app.component.ts&lt;/code&gt;), define a FormGroup for the poll form, handle the submitted data, and set up the form control:&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;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="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;FormBuilder&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;FormGroup&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/forms&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-root&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;./app.component.html&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;styleUrls&lt;/span&gt;&lt;span class="p"&gt;:&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.component.css&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="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;AppComponent&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;options&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="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;BreakFast&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Lunch&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Dinner&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;
  &lt;span class="nl"&gt;pollForm&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;FormGroup&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="k"&gt;private&lt;/span&gt; &lt;span class="nx"&gt;fb&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;FormBuilder&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;pollForm&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;fb&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;group&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
      &lt;span class="na"&gt;pollOptions&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[[]],&lt;/span&gt; &lt;span class="c1"&gt;// Initialize with an empty array&lt;/span&gt;
    &lt;span class="p"&gt;});&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="nf"&gt;submitPoll&lt;/span&gt;&lt;span class="p"&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;selectedOptions&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;pollForm&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="nx"&gt;pollOptions&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Selected Poll Options:&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;selectedOptions&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;h2&gt;
  
  
  Output
&lt;/h2&gt;

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

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

&lt;h3&gt;
  
  
  Conclusion
&lt;/h3&gt;

&lt;p&gt;In this example, we created a custom poll control in Angular using the &lt;code&gt;ControlValueAccessor&lt;/code&gt; interface. Users can select multiple options, and the parent component can handle the selected options. This demonstrates how you can create more complex custom form controls in Angular to suit your application's requirements. You can further enhance this example by adding features like dynamic poll creation and result display.&lt;/p&gt;

&lt;p&gt;Thank's for your time, see you soon :)&lt;/p&gt;

</description>
      <category>angular</category>
      <category>beginners</category>
      <category>webdev</category>
      <category>javascript</category>
    </item>
    <item>
      <title>Optimizing the Performance of an Angular Application</title>
      <dc:creator>Nikhil Sai</dc:creator>
      <pubDate>Mon, 04 Sep 2023 10:03:37 +0000</pubDate>
      <link>https://forem.com/nikhil6076/optimizing-the-performance-of-an-angular-application-27g6</link>
      <guid>https://forem.com/nikhil6076/optimizing-the-performance-of-an-angular-application-27g6</guid>
      <description>&lt;p&gt;"Before learning about performance optimization, first we will learn some ways through which we can analyze the performance of any web application"&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1. Using Chrome DevTools:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;This is a set of web developer tools built into the Google Chrome browser. You can use the Performance tab to record and analyze the runtime performance of your Angular application, such as CPU usage, memory consumption, rendering time, etc.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Open your Angular application in Chrome browser&lt;/li&gt;
&lt;li&gt;Press Ctrl+Shift+I (Windows) or Cmd+Option+I (Mac) to open DevTools&lt;/li&gt;
&lt;li&gt;Click on the Performance tab&lt;/li&gt;
&lt;li&gt;Click on the Record button or press Ctrl+E (Windows) or Cmd+E (Mac) to start recording&lt;/li&gt;
&lt;li&gt;Perform some actions on your Angular application&lt;/li&gt;
&lt;li&gt;Click on the Stop button or press Ctrl+E (Windows) or Cmd+E (Mac) to stop recording&lt;/li&gt;
&lt;li&gt;Analyze the performance results in the DevTools panel&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;2. Using WebPageTest:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;This is a web-based tool that performs website speed tests from multiple locations around the globe using real browsers and at real consumer connection speeds.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Go to &lt;a href="https://www.webpagetest.org/" rel="noopener noreferrer"&gt;https://www.webpagetest.org/&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Enter the URL of your Angular application in the Test Location field&lt;/li&gt;
&lt;li&gt;Choose a test location and a browser from the dropdown menus&lt;/li&gt;
&lt;li&gt;Click on the Start Test button&lt;/li&gt;
&lt;li&gt;Wait for the test to finish and view the performance results on the web page&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;3. Using Angular CLI (Specific to Angular application):&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Open a terminal and navigate to your Angular project folder&lt;/li&gt;
&lt;li&gt;ng build --stats-json // This builds your Angular application and generates a stats.json file in the dist folder&lt;/li&gt;
&lt;li&gt;ng serve --stats-json // This serves your Angular application and generates a stats.json file in the dist folder&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;"Now let's see how we can optimize the Angular application"&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;10 ways to optimize your Angular Application&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;1. Enable production mode:&lt;/strong&gt; This mode performs many significant optimizations not available in a development build, such as ahead-of-time compilation, minification, and tree-shaking.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// Enabling production mode
import { enableProdMode } from '@angular/core';
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
import { AppModule } from './app/app.module';
import { environment } from './environments/environment';
if (environment.production) {
  enableProdMode(); // This enables production mode
}
platformBrowserDynamic().bootstrapModule(AppModule)
  .catch(err =&amp;gt; console.error(err));
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;2. Use AOT compilation:&lt;/strong&gt; This reduces your app payload by removing the Angular compiler from the deployment bundle and producing only the compiled templates. You can use the --aot flag with the ng build or ng serve commands.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;ng build --prod --aot=true
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;3. Use build optimizer:&lt;/strong&gt; This removes Angular specific decorators, constructor parameters and makes it easier for code minifiers to remove unused code. You can use the --buildOptimizer flag with the ng build command.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;ng build --prod --buildOptimizer=true
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;4. Avoid function calls and getters in views:&lt;/strong&gt; These can trigger unnecessary change detection cycles and affect performance. Instead, use properties or pure pipes to display data in views.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;5. Use pure pipes:&lt;/strong&gt; These are only re-evaluated when the input changes, unlike impure pipes that are re-evaluated on every change detection cycle. You can create a pure pipe by setting the pure property to true in the &lt;a class="mentioned-user" href="https://dev.to/pipe"&gt;@pipe&lt;/a&gt; decorator.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;@Pipe({
  name: 'square',
  pure: true // This tells Angular to only recompute the pipe output when the input changes
})
export class SquarePipe implements PipeTransform {
  transform(value: number): number {
    return value * value;
  }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;6.Use lazy loading modules:&lt;/strong&gt; This allows you to load modules on demand, rather than loading them all at once. This reduces the initial loading time and improves performance. You can use the Angular CLI to generate lazy loading modules with the --route flag.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import { NgModule } from '@angular/core';
import { Routes, RouterModule } from '@angular/router';
const routes: Routes = [
  {
    path: 'customers',
    loadChildren: () =&amp;gt; import('./customers/customers.module').then(m =&amp;gt; m.CustomersModule) // This loads the customers module on demand
  },
  {
    path: 'orders',
    loadChildren: () =&amp;gt; import('./orders/orders.module').then(m =&amp;gt; m.OrdersModule) // This loads the orders module on demand
  },
  {
    path: '',
    redirectTo: '',
    pathMatch: 'full'
  }
];
@NgModule({
  imports: [RouterModule.forRoot(routes)],
  exports: [RouterModule]
})
export class AppRoutingModule { }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;7. Use code splitting:&lt;/strong&gt; This is a technique that splits your code into smaller chunks that can be loaded asynchronously. This reduces the size of your main bundle and improves performance. You can use tools such as Webpack or Rollup to implement code splitting.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;8. Use OnPush change detection strategy:&lt;/strong&gt; This tells Angular to only check for changes when the input properties change or an event is triggered. This reduces the number of change detection cycles and improves performance. You can set the changeDetection property to ChangeDetectionStrategy.OnPush in the @Component decorator.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;@Component({
  selector: 'app-my-component',
  templateUrl: './my-component.component.html',
  styleUrls: ['./my-component.component.css'],
  changeDetection: ChangeDetectionStrategy.OnPush // This tells Angular to only check for changes when the input properties change or an event is triggered
})
export class MyComponentComponent implements OnInit {
  @Input() data: any; // This is an input property that can change from outside
  constructor() { }
  ngOnInit(): void {
  }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;9. Use async pipe:&lt;/strong&gt; This is a built-in pipe that subscribes to an observable or promise and returns the latest value. It also handles unsubscribing automatically, which prevents memory leaks. You can use the async pipe in your template with the syntax&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{{ observableOrPromise | async }}.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;10. Use trackBy function on ngFor:&lt;/strong&gt; This is a function that returns a unique identifier for each item in an array. It helps Angular to track changes and reuse existing elements, rather than creating new ones. This improves performance and reduces memory usage. You can use the trackBy function in your template with the syntax *ngFor="let item of items; trackBy: trackById".&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;@Component({
  selector: 'app-my-list',
  template: `
    &amp;lt;ul&amp;gt;
      &amp;lt;li *ngFor="let item of items; trackBy: trackById"&amp;gt;{{item.name}}&amp;lt;/li&amp;gt;
    &amp;lt;/ul&amp;gt;
  `
})
export class MyListComponent {
  items = [
    {id: 1, name: 'Alice'},
    {id: 2, name: 'Bob'},
    {id: 3, name: 'Charlie'}
  ];
  // This function returns the unique identifier of each item
  trackById(index: number, item: any) {
    return item.id;
  }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;em&gt;Above mentioned are some of the ways through which we can optimize our Angular Application. Apart from these you can also use techniques like pagination, cache, storing data in local, session storage and avoiding the unnecessary API calls etc...&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Thank's for your time, see you soon :) &lt;/p&gt;

</description>
      <category>beginners</category>
      <category>angular</category>
      <category>javascript</category>
      <category>web</category>
    </item>
  </channel>
</rss>
