<?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: Amin-Karimi</title>
    <description>The latest articles on Forem by Amin-Karimi (@aminkarimi_sis).</description>
    <link>https://forem.com/aminkarimi_sis</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%2F1896135%2F8d43ccce-15bc-46a1-bc8e-f70bc3313bf8.jpg</url>
      <title>Forem: Amin-Karimi</title>
      <link>https://forem.com/aminkarimi_sis</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/aminkarimi_sis"/>
    <language>en</language>
    <item>
      <title>Goodbye @angular/animations: How to Migrate to Angular 20’s Modern Animation API</title>
      <dc:creator>Amin-Karimi</dc:creator>
      <pubDate>Fri, 26 Sep 2025 05:42:46 +0000</pubDate>
      <link>https://forem.com/aminkarimi_sis/goodbye-angularanimations-how-to-migrate-to-angular-20s-modern-animation-api-37d0</link>
      <guid>https://forem.com/aminkarimi_sis/goodbye-angularanimations-how-to-migrate-to-angular-20s-modern-animation-api-37d0</guid>
      <description>&lt;p&gt;If you’ve been working with Angular for a while, you’ve probably used the familiar &lt;strong&gt;@angular/animations&lt;/strong&gt; API with trigger, state, style, transition, and animate. For years, this was the go-to way to build smooth animations inside Angular apps.&lt;/p&gt;

&lt;p&gt;But with Angular 20, this API has been officially &lt;strong&gt;deprecated&lt;/strong&gt; . The Angular team is pushing for a simpler, more modern, and more maintainable approach that leverages native CSS transitions and the new animate directives (animate.enter, animate.leave).&lt;/p&gt;

&lt;p&gt;This article will walk you through what changed, why it matters, and how to migrate your animations to the new Angular 20 style.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Old Way (Deprecated)
&lt;/h2&gt;

&lt;p&gt;Traditionally, you might have written something like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="nx"&gt;animations&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
  &lt;span class="nf"&gt;trigger&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;detailExpand&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="nf"&gt;state&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;collapsed&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nf"&gt;style&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="na"&gt;height&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;0px&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;minHeight&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;0&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="p"&gt;})),&lt;/span&gt;
    &lt;span class="nf"&gt;state&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;expanded&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nf"&gt;style&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="na"&gt;height&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;*&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="p"&gt;})),&lt;/span&gt;
    &lt;span class="nf"&gt;transition&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;expanded &amp;lt;=&amp;gt; collapsed&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nf"&gt;animate&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;350ms cubic-bezier(0.4, 0.0, 0.2, 1)&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)),&lt;/span&gt;
  &lt;span class="p"&gt;]),&lt;/span&gt;
&lt;span class="p"&gt;],&lt;/span&gt;

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

&lt;/div&gt;



&lt;p&gt;This worked fine, but it came at a cost: complexity, bundle size, and an extra dependency on Angular’s animation engine.&lt;/p&gt;

&lt;h2&gt;
  
  
  The New Way in Angular 20
&lt;/h2&gt;

&lt;p&gt;Now, Angular encourages using DOM insertion/removal animations via animate.enter and animate.leave. Instead of describing states and transitions in TypeScript, you define them directly in your template and CSS.&lt;/p&gt;

&lt;p&gt;Example: Expand/Collapse Animation&lt;br&gt;
Template (component.html)&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;@if(isExpanded) {
&lt;span class="nt"&gt;&amp;lt;div&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;animate.enter=&lt;/span&gt;&lt;span class="s"&gt;"expand"&lt;/span&gt; &lt;span class="na"&gt;animate.leave=&lt;/span&gt;&lt;span class="s"&gt;"collapse"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;p&amp;gt;&lt;/span&gt;Expandable content goes here...&lt;span class="nt"&gt;&amp;lt;/p&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;
&lt;span class="nc"&gt;.expand&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;transition&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;height&lt;/span&gt; &lt;span class="m"&gt;350ms&lt;/span&gt; &lt;span class="n"&gt;cubic-bezier&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="m"&gt;0.4&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="m"&gt;0.0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="m"&gt;0.2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="m"&gt;1&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="nl"&gt;height&lt;/span&gt;&lt;span class="p"&gt;:&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;span class="nc"&gt;.collapse&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;transition&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;height&lt;/span&gt; &lt;span class="m"&gt;350ms&lt;/span&gt; &lt;span class="n"&gt;cubic-bezier&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="m"&gt;0.4&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="m"&gt;0.0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="m"&gt;0.2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="m"&gt;1&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="nl"&gt;height&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;0px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;min-height&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="c"&gt;/* Define the starting style for enter animations */&lt;/span&gt;
&lt;span class="k"&gt;@starting-style&lt;/span&gt; &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;expand&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;height&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;0px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;min-height&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;0&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;
  
  
  Why This Is Better
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Closer to the platform → Uses native CSS transitions.&lt;/li&gt;
&lt;li&gt;Less boilerplate → No more TypeScript-heavy state/transition blocks.&lt;/li&gt;
&lt;li&gt;Future-proof → This is the officially recommended way going forward.&lt;/li&gt;
&lt;li&gt;Smaller bundles → Dropping the @angular/animations dependency reduces bundle size.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Migration Strategy
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;Replace old trigger/state/transition definitions with animate.enter and animate.leave.&lt;/li&gt;
&lt;li&gt;Move animation logic into CSS classes.&lt;/li&gt;
&lt;li&gt;Use @starting-style when needed for enter transitions.&lt;/li&gt;
&lt;li&gt;Control rendering with @if or *ngIf so that elements truly enter/leave the DOM.&lt;/li&gt;
&lt;/ol&gt;

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

&lt;p&gt;This change might feel a little uncomfortable at first if you’ve been using Angular animations for years. But once you adopt the new approach, you’ll realize how much cleaner and more maintainable your code becomes.&lt;/p&gt;

&lt;p&gt;Angular 20’s modern animation API is a big step toward making Angular apps lighter, faster, and closer to web standards.&lt;/p&gt;

&lt;p&gt;So yes — it’s time to say goodbye to @angular/animations and embrace the future. 🚀&lt;/p&gt;

</description>
      <category>angular</category>
      <category>migrate</category>
      <category>animation</category>
      <category>frontend</category>
    </item>
    <item>
      <title>Custom Form Components in Angular: Avoid These Common Mistakes</title>
      <dc:creator>Amin-Karimi</dc:creator>
      <pubDate>Thu, 15 May 2025 18:18:17 +0000</pubDate>
      <link>https://forem.com/aminkarimi_sis/custom-form-components-in-angular-avoid-these-common-mistakes-with-controlvalueaccessor-and-7be</link>
      <guid>https://forem.com/aminkarimi_sis/custom-form-components-in-angular-avoid-these-common-mistakes-with-controlvalueaccessor-and-7be</guid>
      <description>&lt;p&gt;In Angular development, creating custom form components is a powerful way to encapsulate logic and maintain reusable UI elements. However, when integrating these components into Angular’s form ecosystem, many developers ask:&lt;br&gt;
Should I use &lt;strong&gt;ControlValueAccessor&lt;/strong&gt; , or is *&lt;em&gt;FormGroupDirective *&lt;/em&gt; more appropriate for this use case?&lt;br&gt;
The answer depends on the structure of your component and how it interacts with the Angular forms API.&lt;/p&gt;

&lt;p&gt;✅ Use ControlValueAccessor for Single Form Control Components&lt;/p&gt;

&lt;p&gt;If your custom component represents a single form control — such as an input field, toggle switch, dropdown, or similar  —the correct and most idiomatic approach is to implement the *&lt;em&gt;ControlValueAccessor *&lt;/em&gt; interface.&lt;br&gt;
This allows Angular to treat your custom component as if it were a native input element, meaning you can use it seamlessly with FormControl, FormGroup, ngModel, etc.&lt;/p&gt;
&lt;h2&gt;
  
  
  Example Use Case
&lt;/h2&gt;

&lt;p&gt;You're building a custom input with a prefix and suffix icon:&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;my-custom-input&lt;/span&gt; &lt;span class="na"&gt;formControlName=&lt;/span&gt;&lt;span class="s"&gt;"username"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&amp;lt;/my-custom-input&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Since this component only handles a single value, &lt;strong&gt;ControlValueAccessor&lt;/strong&gt; is the ideal solution. You implement writeValue, registerOnChange, and registerOnTouched to hook it into Angular’s change detection and form updates.&lt;/p&gt;

&lt;p&gt;🧠 Use &lt;strong&gt;FormGroupDirective (or ControlContainer)&lt;/strong&gt; for Multi-Control Components&lt;/p&gt;

&lt;p&gt;If your custom component is a composite control that internally manages multiple form controls, then using ControlValueAccessor is not suitable.&lt;/p&gt;

&lt;p&gt;This is common for components like:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;A &lt;strong&gt;date range picker&lt;/strong&gt; that has fromDate and toDate&lt;/li&gt;
&lt;li&gt;A &lt;strong&gt;time range selector&lt;/strong&gt; with startTime and endTime&lt;/li&gt;
&lt;li&gt;An &lt;strong&gt;address form&lt;/strong&gt; that collects street, city, and postal code&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Why ControlValueAccessor Doesn’t Fit
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;ControlValueAccessor&lt;/strong&gt; is designed to bind a single value to a form control. But in a date range picker, you're managing two values (from and to), each of which should be independently controllable, validated, and possibly bound to different parts of the parent form.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Solution: Accept Multiple FormControls via Inputs&lt;/strong&gt;&lt;br&gt;
You can structure your component like this:&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;my-date-range&lt;/span&gt; 
  &lt;span class="na"&gt;[fromControl]=&lt;/span&gt;&lt;span class="s"&gt;"startDate"&lt;/span&gt; 
  &lt;span class="na"&gt;[toControl]=&lt;/span&gt;&lt;span class="s"&gt;"endDate"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/my-date-range&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this pattern:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The parent FormGroup manages both controls.&lt;/li&gt;
&lt;li&gt;The component accepts the FormControls as @Input() bindings.&lt;/li&gt;
&lt;li&gt;Inside the component, you use FormControlDirective or NgControl for validation display, state handling, etc.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Bonus Tip: Avoid Mixing the Two
&lt;/h2&gt;

&lt;p&gt;If you try to mix &lt;strong&gt;ControlValueAccessor&lt;/strong&gt; and manually managed &lt;strong&gt;multiple controls&lt;/strong&gt; inside the same component, you’ll run into conflicts and validation issues. Keep it clean: choose one approach based on your component’s intent.&lt;/p&gt;

&lt;h2&gt;
  
  
  Final Thoughts
&lt;/h2&gt;

&lt;p&gt;Understanding when to use ControlValueAccessor vs FormGroupDirective is essential for writing clean, scalable Angular forms.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;For simple, single-value inputs, implement ControlValueAccessor.&lt;/li&gt;
&lt;li&gt;For composite components managing multiple fields, pass FormControls or FormGroup directly and manage them internally.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This mental model will save you from form headaches and help you build highly reusable and Angular-friendly form components.&lt;/p&gt;

</description>
      <category>angular</category>
      <category>customcomponent</category>
      <category>form</category>
      <category>controlvalueaccessor</category>
    </item>
    <item>
      <title>Stop Ignoring This Key Angular Tool-Your App’s Security Depends on It</title>
      <dc:creator>Amin-Karimi</dc:creator>
      <pubDate>Mon, 20 Jan 2025 08:14:37 +0000</pubDate>
      <link>https://forem.com/aminkarimi_sis/stop-ignoring-this-key-angular-tool-your-apps-security-depends-on-it-fp</link>
      <guid>https://forem.com/aminkarimi_sis/stop-ignoring-this-key-angular-tool-your-apps-security-depends-on-it-fp</guid>
      <description>&lt;p&gt;As a senior frontend developer, security in web applications is not just a checklist item—it’s a non-negotiable priority. Angular, with its robust framework, offers built-in security features to protect your application from vulnerabilities. One powerful tool in this arsenal is DomSanitizer, often underutilized or misunderstood by developers. In this article, we’ll explore why you should always use DomSanitizer when dealing with dynamic content and how it can safeguard your application against XSS attacks.&lt;/p&gt;

&lt;h2&gt;
  
  
  Understanding the Threat: XSS and Dynamic Content
&lt;/h2&gt;

&lt;p&gt;Dynamic content is the backbone of modern web applications. Whether you’re managing user-provided HTML content, binding URLs dynamically, or adding CSS properties programmatically, these operations can introduce risks like XSS (Cross-Site Scripting) attacks. An XSS attack is a serious vulnerability where attackers inject malicious scripts into your application, potentially exposing sensitive user data or compromising functionality.&lt;/p&gt;

&lt;p&gt;Angular’s data binding and templating help mitigate many XSS risks, but when working with dynamic content, additional precautions are necessary. This is where DomSanitizer comes into play.&lt;/p&gt;

&lt;h2&gt;
  
  
  What Is DomSanitizer and Why Is It Important?
&lt;/h2&gt;

&lt;p&gt;DomSanitizer is a service provided by Angular that helps clean and sanitize untrusted values before they are used in the DOM. It acts as a gatekeeper, ensuring that only safe content is rendered, thereby reducing the risk of XSS attacks. Let’s dive into how you can use DomSanitizer effectively in your Angular applications.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Key Features of DomSanitizer&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Sanitize URLs: Prevents malicious links by ensuring that dynamically bound URLs are safe for navigation or embedding.&lt;/li&gt;
&lt;li&gt;Sanitize HTML: Strips out potentially dangerous elements, such as script tags, from user-generated or dynamic HTML content.&lt;/li&gt;
&lt;li&gt;Sanitize CSS: Cleans dynamically added styles to block potentially harmful CSS that could manipulate the layout or leak sensitive information.&lt;/li&gt;
&lt;li&gt;Bypass Security with Caution: Provides explicit methods like bypassSecurityTrustHtml, bypassSecurityTrustStyle, and bypassSecurityTrustUrl for developers to override Angular’s strict security measures when absolutely necessary—but only for trusted inputs.
These features make DomSanitizer an essential tool for any Angular developer handling untrusted content.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Example: Using DomSanitizer in Angular 19 with Standalone Components
&lt;/h2&gt;

&lt;p&gt;Let’s see how to use DomSanitizer in a real-world example using Angular 19 and the &lt;strong&gt;new inject()&lt;/strong&gt; method for dependency injection. Here’s a simple standalone component that displays sanitized HTML content:&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="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;inject&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;DomSanitizer&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;SafeHtml&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;@angular/platform-browser&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="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-safe-content&lt;/span&gt;&lt;span class="dl"&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="na"&gt;template&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;`
    &amp;lt;div [innerHTML]="sanitizedHtml"&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;SafeContentComponent&lt;/span&gt; &lt;span class="kr"&gt;implements&lt;/span&gt; &lt;span class="nx"&gt;OnInit&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;sanitizer&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;inject&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;DomSanitizer&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="nl"&gt;sanitizedHtml&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;SafeHtml&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="k"&gt;void&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;unsafeHtml&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;`&amp;lt;h1&amp;gt;Welcome!&amp;lt;/h1&amp;gt;&amp;lt;script&amp;gt;alert('XSS Attack');&amp;lt;/script&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;sanitizedHtml&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;sanitizer&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;bypassSecurityTrustHtml&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;unsafeHtml&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;Explanation&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Standalone Component: This example uses Angular 19’s standalone components for simplicity.&lt;/li&gt;
&lt;li&gt;inject() Method: The new inject() function is used to retrieve the DomSanitizer service, eliminating the need for constructor injection.&lt;/li&gt;
&lt;li&gt;Sanitizing Content: The bypassSecurityTrustHtml() method ensures that only safe HTML content is displayed.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Best Practices When Using DomSanitizer
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;Minimize Usage of Bypass Methods: While bypassSecurityTrustHtml and similar methods can be useful, use them sparingly and only when absolutely necessary. Always prefer Angular’s built-in security mechanisms.&lt;/li&gt;
&lt;li&gt;Validate Input: Ensure that any user-provided data is validated and sanitized before using it in the DOM.&lt;/li&gt;
&lt;li&gt;Keep Dependencies Updated: Regularly update Angular to benefit from the latest security patches and features.&lt;/li&gt;
&lt;/ol&gt;

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

&lt;p&gt;DomSanitizer is an indispensable tool for protecting your Angular applications from XSS attacks. By incorporating it into your development workflow and following best practices, you can build secure and robust applications. Remember, security is a shared responsibility, and leveraging Angular’s powerful features is a great way to stay ahead of potential threats.&lt;/p&gt;

&lt;p&gt;Start implementing DomSanitizer today and make your Angular applications safer for everyone!&lt;/p&gt;

</description>
      <category>angular</category>
      <category>xss</category>
      <category>security</category>
    </item>
    <item>
      <title>Angular Sample project with interceptors,....</title>
      <dc:creator>Amin-Karimi</dc:creator>
      <pubDate>Thu, 28 Nov 2024 06:53:18 +0000</pubDate>
      <link>https://forem.com/aminkarimi_sis/angular-sample-project-with-interceptors-223a</link>
      <guid>https://forem.com/aminkarimi_sis/angular-sample-project-with-interceptors-223a</guid>
      <description>&lt;div class="ltag__link"&gt;
  &lt;a href="/aminkarimi_sis" class="ltag__link__link"&gt;
    &lt;div class="ltag__link__pic"&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%2Fuser%2Fprofile_image%2F1896135%2F8d43ccce-15bc-46a1-bc8e-f70bc3313bf8.jpg" alt="aminkarimi_sis"&gt;
    &lt;/div&gt;
  &lt;/a&gt;
  &lt;a href="https://dev.to/aminkarimi_sis/quick-start-with-the-angular-181-sample-project-a-simple-and-practical-solution-for-developers-2k54" class="ltag__link__link"&gt;
    &lt;div class="ltag__link__content"&gt;
      &lt;h2&gt;Quick Start with the Angular 18.1 Sample Project - A Simple and Practical Solution for Developers!&lt;/h2&gt;
      &lt;h3&gt;Amin-Karimi ・ Sep 27 '24&lt;/h3&gt;
      &lt;div class="ltag__link__taglist"&gt;
        &lt;span class="ltag__link__tag"&gt;#angular&lt;/span&gt;
        &lt;span class="ltag__link__tag"&gt;#frontend&lt;/span&gt;
        &lt;span class="ltag__link__tag"&gt;#tutorial&lt;/span&gt;
        &lt;span class="ltag__link__tag"&gt;#opensource&lt;/span&gt;
      &lt;/div&gt;
    &lt;/div&gt;
  &lt;/a&gt;
&lt;/div&gt;


</description>
    </item>
    <item>
      <title>Boost Your Angular 19 App’s Speed with @defer: A Must-Have for Lightning-Fast UX</title>
      <dc:creator>Amin-Karimi</dc:creator>
      <pubDate>Thu, 28 Nov 2024 06:34:42 +0000</pubDate>
      <link>https://forem.com/aminkarimi_sis/boost-your-angular-19-apps-speed-with-defer-a-must-have-for-lightning-fast-ux-9kp</link>
      <guid>https://forem.com/aminkarimi_sis/boost-your-angular-19-apps-speed-with-defer-a-must-have-for-lightning-fast-ux-9kp</guid>
      <description>&lt;p&gt;In Angular 19, the &lt;strong&gt;&lt;code&gt;@defer&lt;/code&gt;&lt;/strong&gt; directive is a game-changing feature designed to optimize performance by deferring the loading of non-essential components. This approach improves initial load times, enhances the user experience, and conserves resources—perfect for building modern, fast, and efficient web applications.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why &lt;code&gt;@defer&lt;/code&gt; Matters
&lt;/h2&gt;

&lt;p&gt;When you use &lt;strong&gt;&lt;code&gt;@defer,&lt;/code&gt;&lt;/strong&gt; Angular waits to load certain components until they're needed, leveraging the IntersectionObserver API to detect when an element is about to enter the viewport. Unlike traditional lazy loading, &lt;code&gt;@defer&lt;/code&gt; provides more granular control with options like &lt;br&gt;
&lt;strong&gt;&lt;code&gt;@placeholder,&lt;/code&gt;&lt;/strong&gt; &lt;strong&gt;&lt;code&gt;@loading,&lt;/code&gt;&lt;/strong&gt; and &lt;strong&gt;&lt;code&gt;@error&lt;/code&gt;&lt;/strong&gt; for smoother UX.&lt;/p&gt;
&lt;h2&gt;
  
  
  Example: Deferred Image Loading
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Here's a simple example that demonstrates how to use &lt;code&gt;@defer&lt;/code&gt; to delay the loading of images:&lt;/strong&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="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;h1&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="nx"&gt;Optimized&lt;/span&gt; &lt;span class="nx"&gt;Image&lt;/span&gt; &lt;span class="nx"&gt;Loading&lt;/span&gt; &lt;span class="kd"&gt;with&lt;/span&gt; &lt;span class="s2"&gt;`@defer`&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/h1&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;&lt;span class="p"&gt;@&lt;/span&gt;&lt;span class="nd"&gt;defer&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;lt;&lt;/span&gt;&lt;span class="nx"&gt;app&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nx"&gt;images&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/app-images&lt;/span&gt;&lt;span class="err"&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="nd"&gt;placeholder&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;minimum&lt;/span&gt; &lt;span class="mi"&gt;500&lt;/span&gt;&lt;span class="nx"&gt;ms&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;lt;&lt;/span&gt;&lt;span class="nx"&gt;p&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="nx"&gt;Loading&lt;/span&gt; &lt;span class="nx"&gt;Images&lt;/span&gt;&lt;span class="p"&gt;...&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/p&lt;/span&gt;&lt;span class="err"&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="nd"&gt;loading&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;after&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="nx"&gt;s&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nx"&gt;minimum&lt;/span&gt; &lt;span class="mi"&gt;500&lt;/span&gt;&lt;span class="nx"&gt;ms&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;lt;&lt;/span&gt;&lt;span class="nx"&gt;p&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="nx"&gt;Still&lt;/span&gt; &lt;span class="nx"&gt;loading&lt;/span&gt;&lt;span class="p"&gt;...&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/p&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Key Features of &lt;code&gt;@defer&lt;/code&gt;
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;@placeholder:&lt;/code&gt;&lt;/strong&gt; Displays temporary content while waiting for the deferred component to load.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;@loading:&lt;/code&gt;&lt;/strong&gt; Shows feedback during the loading process, avoiding awkward visual "flickers."&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Conditional Triggers:&lt;/strong&gt; Load components based on various conditions like:&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;on hover:&lt;/strong&gt; Load when the user hovers over an element.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;on timer:&lt;/strong&gt; Load after a specified delay (&lt;code&gt;@defer&lt;/code&gt; (on timer(2s)) {}).&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;on interaction:&lt;/strong&gt; Load after user interaction such as clicks or key presses.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Why It’s a Game-Changer
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;&lt;code&gt;@defer&lt;/code&gt;&lt;/strong&gt; significantly reduces the size of your initial application bundle, speeding up the first meaningful paint. It’s especially beneficial for large apps or resource-intensive components, enhancing performance on both fast and slow connections alike.&lt;/p&gt;

</description>
      <category>angular</category>
      <category>frontend</category>
      <category>defer</category>
      <category>lazyload</category>
    </item>
    <item>
      <title>The Ultimate Guide to Cleaner and Smarter Route Data Binding For Angular Projects!</title>
      <dc:creator>Amin-Karimi</dc:creator>
      <pubDate>Fri, 01 Nov 2024 08:19:40 +0000</pubDate>
      <link>https://forem.com/aminkarimi_sis/the-ultimate-guide-to-cleaner-and-smarter-route-data-binding-for-angular-projects-4mof</link>
      <guid>https://forem.com/aminkarimi_sis/the-ultimate-guide-to-cleaner-and-smarter-route-data-binding-for-angular-projects-4mof</guid>
      <description>&lt;p&gt;In Angular applications, developers frequently need to pass data through routes to different components. Traditionally, we would subscribe to ActivatedRoute to retrieve this data, leading to boilerplate code and potential pitfalls with manual subscription management. Angular introduces a game-changer: &lt;strong&gt;withComponentInputBinding()&lt;/strong&gt;, which enables automatic, declarative binding of route data to component inputs. This feature simplifies our code, reduces dependencies, and makes our routing setup far more readable.&lt;/p&gt;

&lt;p&gt;In this guide, let’s dive deep into withComponentInputBinding(), understanding how it works and seeing it in action with sample code.&lt;/p&gt;

&lt;h2&gt;
  
  
  What is withComponentInputBinding()?
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;withComponentInputBinding()&lt;/strong&gt;  is a new method available in Angular’s router configuration that binds route data directly to component inputs. This removes the need to manually subscribe to ActivatedRoute to fetch route data, and instead, data is mapped to component properties automatically.&lt;/p&gt;

&lt;p&gt;Key &lt;strong&gt;Benefits&lt;/strong&gt; of Using &lt;strong&gt;withComponentInputBinding()&lt;/strong&gt;:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Reduces Boilerplate Code: No more manual subscriptions to ActivatedRoute.&lt;/li&gt;
&lt;li&gt;Improves Readability and Maintainability: Routes clearly define the data they pass, enhancing code clarity.&lt;/li&gt;
&lt;li&gt;Cleaner, Safer Components: Avoids the potential pitfalls of manual subscription management and promotes a declarative style.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  How to Use withComponentInputBinding()
&lt;/h2&gt;

&lt;p&gt;Step 1: Define the Route with Data&lt;br&gt;
Set up your route with predefined data or parameters in app.config.ts Then, use withComponentInputBinding() to link this data directly to component properties.&lt;/p&gt;

&lt;p&gt;Step 2: Bind Route Data to Component Inputs&lt;br&gt;
Define inputs in your component that match the route data keys. Angular will automatically map the data to these inputs.&lt;/p&gt;

&lt;p&gt;app.config.ts&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="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;ApplicationConfig&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;provideRouter&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;withComponentInputBinding&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;@angular/router&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;routes&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;./app.routes&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;appConfig&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;ApplicationConfig&lt;/span&gt; &lt;span class="o"&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="nf"&gt;provideRouter&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;routes&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nf"&gt;withComponentInputBinding&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;ProductComponent&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="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;input&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&lt;/span&gt;&lt;span class="dl"&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="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="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;styleUrl&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.scss&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;ProductComponent&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
   &lt;span class="nx"&gt;productId&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;input&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;string&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&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="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Product Route&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="p"&gt;{&lt;/span&gt;
        &lt;span class="nl"&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;product/:productId&lt;/span&gt;&lt;span class="dl"&gt;'&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;ProductComponent&lt;/span&gt;
     &lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



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

&lt;p&gt;withComponentInputBinding() is a fantastic enhancement for developers looking to create cleaner, more maintainable Angular applications. By removing the need for manual subscriptions, this feature streamlines data handling between routes and components, ultimately leading to more readable and reliable code.&lt;/p&gt;

&lt;p&gt;Give withComponentInputBinding() a try in your Angular projects to experience the benefits of simpler, smarter route data management.&lt;/p&gt;

</description>
      <category>angular</category>
      <category>route</category>
      <category>frontend</category>
      <category>typescript</category>
    </item>
    <item>
      <title>Quick Start with the Angular 18.1 Sample Project - A Simple and Practical Solution for Developers!</title>
      <dc:creator>Amin-Karimi</dc:creator>
      <pubDate>Fri, 27 Sep 2024 07:55:30 +0000</pubDate>
      <link>https://forem.com/aminkarimi_sis/quick-start-with-the-angular-181-sample-project-a-simple-and-practical-solution-for-developers-2k54</link>
      <guid>https://forem.com/aminkarimi_sis/quick-start-with-the-angular-181-sample-project-a-simple-and-practical-solution-for-developers-2k54</guid>
      <description>&lt;p&gt;Hey fellow developers!&lt;/p&gt;

&lt;p&gt;Whether you're new to Angular 18.1 or just looking for a solid, well-structured foundation for your projects, this open-source repo is exactly what you need! Designed with a monolithic architecture, this project keeps things simple yet powerful, allowing for quick setup and easy organization.&lt;/p&gt;

&lt;h2&gt;
  
  
  Repo link
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://github.com/Amin-Karimi/angular-sample-small-project" rel="noopener noreferrer"&gt;Check the GitHub repo here!&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Why this project?&lt;/strong&gt;&lt;br&gt;
This template is perfect for kickstarting Angular applications. With its monolithic architecture, managing components and services becomes seamless, focusing on functionality without added complexity.&lt;/p&gt;

&lt;p&gt;Plus, it’s a growing project, and your &lt;strong&gt;feedback&lt;/strong&gt; is essential to its improvement. Please check out the repo, and feel free to &lt;strong&gt;share&lt;/strong&gt; your thoughts. If you find it helpful, I’d love it if you could introduce it to your colleagues and friends!&lt;/p&gt;

</description>
      <category>angular</category>
      <category>frontend</category>
      <category>tutorial</category>
      <category>opensource</category>
    </item>
    <item>
      <title>Mastering Progressive Web Apps(PWA) with Angular 18: A Senior Developer's Deep Dive</title>
      <dc:creator>Amin-Karimi</dc:creator>
      <pubDate>Mon, 09 Sep 2024 05:22:47 +0000</pubDate>
      <link>https://forem.com/aminkarimi_sis/mastering-progressive-web-appspwa-with-angular-18-a-senior-developers-deep-dive-1698</link>
      <guid>https://forem.com/aminkarimi_sis/mastering-progressive-web-appspwa-with-angular-18-a-senior-developers-deep-dive-1698</guid>
      <description>&lt;p&gt;&lt;strong&gt;Progressive Web Apps (PWAs)&lt;/strong&gt; have transformed the landscape of web development, enabling developers to merge the power of web technologies with the seamless user experience of native mobile apps. Now, with Angular 18, developers are equipped with cutting-edge tools to elevate PWA development to a whole new level. This version introduces powerful features that simplify the creation of high-performance, user-friendly applications, making the development process smoother than ever. In this comprehensive guide, we’ll explore the key updates in Angular 18, walk through a hands-on example of building a PWA, and discuss why PWAs are essential for modern web development.&lt;/p&gt;

&lt;h2&gt;
  
  
  Angular 18: Groundbreaking Updates for PWAs
&lt;/h2&gt;

&lt;p&gt;Angular 18 introduces several pivotal improvements aimed at enhancing performance, simplifying the developer experience, and increasing user satisfaction. These enhancements break through traditional bottlenecks, giving developers more flexibility and control to build faster, more stable, and feature-rich PWAs.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Zoneless Change Detection with Signals&lt;/strong&gt;&lt;br&gt;
One of the standout updates in Angular 18 is the experimental introduction of zoneless change detection. In previous versions, zone.js handled change detection, which often introduced performance overhead in larger apps. Angular 18 reduces this by offering a signal-based reactivity model, eliminating the need for zone.js and significantly improving rendering times. This is a game-changer for PWA development, where performance is critical for delivering a smooth user experience.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Partial Hydration for Faster Load Times&lt;/strong&gt;&lt;br&gt;
Angular 18 also introduces partial hydration, a technique that prioritizes rendering essential components while deferring non-critical elements. This is particularly beneficial for PWAs, where the initial load time is crucial for user perception. With partial hydration, your app feels more responsive, even on slower network connections, improving both performance and user engagement.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Improved Service Workers&lt;/strong&gt;&lt;br&gt;
Service workers are the backbone of any PWA, enabling offline capabilities and caching critical resources. Angular 18 enhances service workers by offering finer control over caching strategies, allowing developers to better manage background synchronization and updates. These improvements result in a more reliable offline experience, faster load times, and smoother updates.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Full Support for TypeScript 5.4&lt;/strong&gt;&lt;br&gt;
With TypeScript 5.4 support, Angular 18 brings powerful features such as template literal types and enhanced readonly properties, helping developers write cleaner, safer code. For PWA development, this means stronger type safety and easier maintenance, which are crucial for building scalable, robust applications.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Building a PWA in Angular 18
&lt;/h2&gt;

&lt;p&gt;Let’s now apply these updates by transforming a standard Angular project into a fully-functional PWA. PWAs offer fast loading times, offline functionality, and native-like experiences—all within the browser.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 1: Adding PWA Functionality&lt;/strong&gt;&lt;br&gt;
&lt;code&gt;ng add @angular/pwa&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;This command automatically configures essential files, including the service worker (ngsw-config.json) and the manifest file (manifest.webmanifest), which define the app’s appearance and behavior when installed on a device.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 2: Configure the Manifest&lt;/strong&gt;&lt;br&gt;
The manifest.webmanifest file lets you customize how your PWA appears and functions when installed. You can adjust the app’s name, theme color, and icon settings:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{
  "name": "My Angular PWA",
  "short_name": "AngularPWA",
  "theme_color": "#1976d2",
  "background_color": "#ffffff",
  "display": "standalone",
  "start_url": "/",
  "icons": [
    {
      "src": "assets/icons/icon-192x192.png",
      "sizes": "192x192",
      "type": "image/png"
    }
  ]
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This configuration helps browsers render the app as a standalone, native-like application when added to the home screen.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 3: Optimizing the Service Worker&lt;/strong&gt;&lt;br&gt;
In ngsw-config.json, you can fine-tune how assets are cached. For example, you can prefetch core assets like HTML, CSS, and JavaScript for quick loading, while deferring other resources like images:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{
  "index": "/index.html",
  "assetGroups": [
    {
      "name": "app",
      "installMode": "prefetch",
      "resources": {
        "files": ["/favicon.ico", "/index.html", "/*.css", "/*.js"]
      }
    },
    {
      "name": "assets",
      "installMode": "lazy",
      "resources": {
        "files": ["/assets/**"]
      }
    }
  ]
}

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

&lt;/div&gt;



&lt;p&gt;This setup ensures essential assets are loaded immediately, while less critical resources are cached only when needed.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 4: Building and Deploying the Application&lt;/strong&gt;&lt;br&gt;
Finally, build the project for production:&lt;br&gt;
&lt;code&gt;ng build --configuration production&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Once built, ensure the app is served over HTTPS, as service workers require a secure context. You can now test your PWA in both desktop and mobile browsers, where it will behave like a native app with full offline functionality, thanks to service workers.&lt;/p&gt;

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

&lt;p&gt;As one of the most powerful web development frameworks available, Angular 18 solidifies its position with tools that make developing performant, user-friendly PWAs more accessible than ever. By leveraging Angular 18’s powerful features—improved load times, enhanced offline capabilities, and seamless multi-device experiences—you can build world-class Progressive Web Apps that meet and exceed user expectations.&lt;/p&gt;

</description>
      <category>angular</category>
      <category>pwa</category>
      <category>frontend</category>
      <category>programming</category>
    </item>
    <item>
      <title>Migration to the `inject` function in components,...</title>
      <dc:creator>Amin-Karimi</dc:creator>
      <pubDate>Fri, 16 Aug 2024 07:01:14 +0000</pubDate>
      <link>https://forem.com/aminkarimi_sis/migration-to-the-inject-function-in-components-2obc</link>
      <guid>https://forem.com/aminkarimi_sis/migration-to-the-inject-function-in-components-2obc</guid>
      <description>&lt;p&gt;&lt;strong&gt;Angular 18&lt;/strong&gt; has introduced a powerful and flexible feature: the &lt;strong&gt;inject()&lt;/strong&gt; function. This function redefines how dependency injection (DI) works in Angular, making it more intuitive, especially in complex scenarios. Let's dive into how this function works, why it's a game-changer, and how you can use it with examples straight from the official Angular documentation.&lt;/p&gt;

&lt;h2&gt;
  
  
  Command for Migration(Angular 18.2)
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;ng generate @angular/core:inject
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  What is the inject() Function?
&lt;/h2&gt;

&lt;p&gt;Traditionally, Angular's DI relied heavily on constructor injection. You'd typically declare dependencies in a class constructor, and Angular would resolve them for you:&lt;br&gt;
&lt;strong&gt;Before:&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;typescript

import { HttpClient } from '@angular/common/http';
export class test {
constructor(private http: HttpClient) {}
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;While this works perfectly fine, it has limitations—especially when working with services that require conditional or dynamic instantiation.&lt;/p&gt;

&lt;p&gt;The inject() function, however, allows you to inject dependencies directly within a function or method, bypassing the constructor. This is particularly useful in standalone functions or in scenarios where the dependency isn’t needed until later in the method logic.&lt;/p&gt;

&lt;h2&gt;
  
  
  How to Use inject()?
&lt;/h2&gt;

&lt;p&gt;Here’s a simple example. Let's say you have a service MyService that you want to use in a function outside of a class:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;typescript

import { inject } from '@angular/core';
import { MyService } from './my-service';

@Component()
export class MyComp {
  myService = inject(MyService);

test() {
  myService.doSomething();
}
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this example, inject(MyService) retrieves the instance of MyService just like it would if it were injected in a constructor. This makes the inject() function highly versatile for various scenarios, including utility functions or deeply nested services.&lt;/p&gt;

&lt;h2&gt;
  
  
  Advanced Example: Injecting with Custom Options
&lt;/h2&gt;

&lt;p&gt;Angular’s &lt;strong&gt;inject()&lt;/strong&gt; also supports advanced use cases where you might need to pass additional options. For instance, suppose you want to inject a service with a fallback value if the service isn't provided:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;typescript

import { inject } from '@angular/core';
import { MyService } from './my-service';

@Component()
export class MyComp {
 private  myService = inject(MyService, { optional: true });
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Why Should You Care?
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Improved Flexibility: inject() provides more control over when and how dependencies are injected.&lt;/li&gt;
&lt;li&gt;Better Readability: Dependencies are now more explicitly tied to their usage.&lt;/li&gt;
&lt;li&gt;Enhanced Performance: Conditional and lazy loading of dependencies can reduce memory footprint and improve load times.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Angular 18's inject() function is not just a minor update—it's a fundamental shift in how you can write, manage, and optimize your Angular applications. By using this new approach, you can write cleaner, more efficient, and more maintainable code.&lt;/p&gt;

</description>
      <category>angular</category>
      <category>inject</category>
      <category>learning</category>
    </item>
    <item>
      <title>Angular Typed Forms: Precision and Power in Form Management</title>
      <dc:creator>Amin-Karimi</dc:creator>
      <pubDate>Tue, 13 Aug 2024 06:32:32 +0000</pubDate>
      <link>https://forem.com/aminkarimi_sis/angular-typed-forms-precision-and-power-in-form-management-3ik7</link>
      <guid>https://forem.com/aminkarimi_sis/angular-typed-forms-precision-and-power-in-form-management-3ik7</guid>
      <description>&lt;p&gt;&lt;strong&gt;In modern web development&lt;/strong&gt;, ensuring type safety and consistency is crucial. Angular has introduced Typed Forms as a powerful enhancement over traditional forms. This article explores how Typed Forms elevate form management by providing strict type enforcement, reducing runtime errors, and enhancing developer productivity.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why Typed Forms?
&lt;/h2&gt;

&lt;p&gt;In previous versions of Angular, forms were flexible but lacked strong type safety, leading to potential bugs. Typed Forms address this by ensuring that each form control, group, or array is strictly typed, allowing for better code quality and safer refactoring.&lt;/p&gt;

&lt;h2&gt;
  
  
  Getting Started with Typed Forms:
&lt;/h2&gt;

&lt;p&gt;Here's how you can start using Typed Forms:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import { FormGroup, FormControl } from '@angular/forms';

interface UserForm {
  name: FormControl&amp;lt;string&amp;gt;;
  age: FormControl&amp;lt;number&amp;gt;;
}

const userForm = new FormGroup&amp;lt;UserForm&amp;gt;({
  name: new FormControl(''),
  age: new FormControl(0),
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;In this example&lt;/strong&gt;, the UserForm interface ensures that each form control is strongly typed, making it clear what types of values are expected and reducing the chances of runtime errors.&lt;/p&gt;

&lt;h2&gt;
  
  
  Advanced Validation with Typed Forms:
&lt;/h2&gt;

&lt;p&gt;Typed Forms shine when it comes to custom validation. For instance, creating a custom validator for a FormControl is now straightforward:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import { AbstractControl, ValidationErrors } from '@angular/forms';

function ageValidator(control: AbstractControl&amp;lt;number&amp;gt;): ValidationErrors | null {
  return control.value &amp;gt;= 18 ? null : { ageInvalid: true };
}

userForm.controls.age.setValidators(ageValidator);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This type enforcement makes it easier to catch issues during development, ensuring that your validators and controls are always in sync.&lt;/p&gt;

&lt;h2&gt;
  
  
  Benefits of Typed Forms:
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Type Safety: Reduces bugs and improves maintainability by catching type mismatches at compile time.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Enhanced Intellisense: Provides better auto-completion and suggestions in IDEs, speeding up development.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Safer Refactoring: Refactoring is less error-prone since types are enforced, making large codebases easier to manage.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

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

&lt;p&gt;Typed Forms in Angular represent a significant leap forward in form management, offering both precision and power. As Angular continues to evolve, Typed Forms are set to become a standard practice for developers seeking to build robust, scalable applications. If you're not yet using Typed Forms, now is the time to start—embrace the future of form handling in Angular!&lt;/p&gt;

</description>
      <category>angular</category>
      <category>forms</category>
      <category>frontend</category>
      <category>learning</category>
    </item>
    <item>
      <title>Simplifying Form Management in Angular with FormGroupDirective</title>
      <dc:creator>Amin-Karimi</dc:creator>
      <pubDate>Wed, 07 Aug 2024 11:26:21 +0000</pubDate>
      <link>https://forem.com/aminkarimi_sis/simplifying-form-management-in-angular-with-formgroupdirective-181n</link>
      <guid>https://forem.com/aminkarimi_sis/simplifying-form-management-in-angular-with-formgroupdirective-181n</guid>
      <description>&lt;p&gt;As an Angular developer, managing forms can sometimes be a daunting task, especially when using ngValueAccessor. While ngValueAccessor is powerful, it often requires implementing numerous functions to handle value retrieval and updates for our form elements. Recently, I transitioned to using FormGroupDirective, and it has significantly streamlined the process. Here’s why this switch was a game-changer for me and my team:&lt;/p&gt;

&lt;h2&gt;
  
  
  Why FormGroupDirective?
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Simplicity in Implementation&lt;br&gt;
With FormGroupDirective, much of the boilerplate code required by ngValueAccessor is eliminated. This means less time writing repetitive code and more time focusing on business logic.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Better Synchronization of Values&lt;br&gt;
FormGroupDirective automatically synchronizes values, so there’s no need to write additional functions for value retrieval and setting. This makes the code cleaner and easier to maintain.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Improved Code Readability&lt;br&gt;
Code written with FormGroupDirective is significantly more readable and understandable. This is especially beneficial for the entire development team, including newcomers.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Greater Flexibility&lt;br&gt;
Using FormGroupDirective provides more flexibility in managing forms, allowing us to easily handle more complex forms.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Let's dive into a practical example to illustrate how FormGroupDirective can simplify form management.&lt;/p&gt;

&lt;h2&gt;
  
  
  Before: Using ngValueAccessor
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import { Component, forwardRef } from '@angular/core';
import { NG_VALUE_ACCESSOR, ControlValueAccessor } from '@angular/forms';

@Component({
  selector: 'app-custom-input',
  template: `
    &amp;lt;input type="text" [value]="value" (input)="onInput($event.target.value)" /&amp;gt;
  `,
  providers: [
    {
      provide: NG_VALUE_ACCESSOR,
      useExisting: forwardRef(() =&amp;gt; CustomInputComponent),
      multi: true,
    },
  ],
})
export class CustomInputComponent implements ControlValueAccessor {
  value: string;

  onChange: any = () =&amp;gt; {};
  onTouched: any = () =&amp;gt; {};

  writeValue(value: any): void {
    this.value = value;
  }

  registerOnChange(fn: any): void {
    this.onChange = fn;
  }

  registerOnTouched(fn: any): void {
    this.onTouched = fn;
  }

  onInput(value: string) {
    this.value = value;
    this.onChange(value);
  }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  After: Using FormGroupDirective
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import { Component, Input } from '@angular/core';
import { FormGroup, FormGroupDirective, ReactiveFormsModule } from '@angular/forms';

@Component({
  selector: 'app-custom-form',
  template: `
    &amp;lt;form [formGroup]="form"&amp;gt;
      &amp;lt;input [formControlName]="controlName" /&amp;gt;
    &amp;lt;/form&amp;gt;
  `,
  standalone:true,
  imports:[ReactiveFormsModule]
})
export class CustomFormComponent {
  form!: FormGroup;
  @Input({ required: true }) controlName!: string

  constructor(private _rootFormGroup: FormGroupDirective,) {
    this.form = this._rootFormGroup.control as FormGroup;
  }

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

&lt;/div&gt;



</description>
      <category>angular</category>
      <category>formgroupdirective</category>
      <category>learning</category>
      <category>frontend</category>
    </item>
  </channel>
</rss>
