<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by GNirujananthan on Medium]]></title>
        <description><![CDATA[Stories by GNirujananthan on Medium]]></description>
        <link>https://medium.com/@gnirujananthan?source=rss-a5570e78fe53------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*HHYATdM2cfYcO9E8AEaeNw.jpeg</url>
            <title>Stories by GNirujananthan on Medium</title>
            <link>https://medium.com/@gnirujananthan?source=rss-a5570e78fe53------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 21 Nov 2026 03:24:08 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@gnirujananthan/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Mastering Angular Forms: A Practical Guide to Reactive and Template-Driven Approaches]]></title>
            <link>https://medium.com/@gnirujananthan/forms-in-angular-8466ba1c67e2?source=rss-a5570e78fe53------2</link>
            <guid isPermaLink="false">https://medium.com/p/8466ba1c67e2</guid>
            <dc:creator><![CDATA[GNirujananthan]]></dc:creator>
            <pubDate>Tue, 04 Nov 2025 07:00:53 GMT</pubDate>
            <atom:updated>2025-11-04T07:02:40.515Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/470/0*IvLMLpOEcw4AW2H2.jpg" /><figcaption>formImg.png</figcaption></figure><p>There are two types of forms used in angular</p><p>they are</p><ol><li><strong>Reactive Forms</strong></li><li><strong>Template Driven Forms</strong></li></ol><p>let’s see deeply</p><h3>Core Concept</h3><h3><strong>1. Reactive Forms</strong></h3><p>Form type uses ReactiveFormsModule , Reactive forms, also known as <strong>model-driven forms</strong>, are a powerful Angular approach for building forms where the <strong>form’s structure, data model, and validation logic are defined programmatically in the component’s code</strong> using classes like FormControl, FormGroup, and FormArray. They offer <strong>synchronous access to form data</strong>, embrace <strong>immutability</strong>, and leverage <strong>observable streams (RxJS)</strong> for tracking real-time changes, making them ideal for complex forms, dynamic validation, and scalable applications.</p><p><strong>Reactive Forms Usage in this Countries Component</strong></p><pre><br>&lt;input type=&quot;text&quot; [formControl]=&quot;searchControl&quot; placeholder=&quot;Search countries...&quot; class=&quot;border p-2 rounded w-full search-input&quot; /&gt;</pre><pre><br>searchControl = new FormControl(&#39;&#39;);</pre><p>So here’s what’s happening:</p><ul><li>FormControl (from Reactive Forms) binds the &lt;input&gt; field directly to a variable in your TypeScript code.</li><li>It’s not using ngModel (template-driven) but <strong>Reactive Forms</strong>, allowing programmatic control.</li><li>You can subscribe to its valueChanges observable to filter countries in real-time.</li></ul><p>Example (in the .ts file):</p><pre>this.searchControl.valueChanges.subscribe(value =&gt; {<br>  this.filteredCountries = this.countries.filter(country =&gt;<br>    country.name.toLowerCase().includes(value.toLowerCase())<br>  );<br>});</pre><p>that’s <strong>Reactive Form behavior</strong> — reactive, observable-based, and entirely controlled from TypeScript.</p><p><strong>Reactive Forms Inside </strong><strong>&lt;app-add-country&gt;</strong></p><pre>&lt;app-add-country #countryModal [modelType]=&quot;selectedType&quot; (countryAdded)=&quot;handleGetCountries($event)&quot;&gt;&lt;/app-add-country&gt;</pre><pre>countryForm = this.fb.group({<br>  countryCode: [&#39;&#39;, [Validators.required, Validators.minLength(2)]],<br>  name: [&#39;&#39;, Validators.required]<br>});</pre><pre>&lt;form [formGroup]=&quot;countryForm&quot; (ngSubmit)=&quot;onSubmit()&quot;&gt;<br>  &lt;input formControlName=&quot;countryCode&quot; placeholder=&quot;Country Code&quot; /&gt;<br>  &lt;input formControlName=&quot;name&quot; placeholder=&quot;Country Name&quot; /&gt;<br>  &lt;button type=&quot;submit&quot;&gt;{{ modelType === &#39;Add&#39; ? &#39;Add&#39; : &#39;Update&#39; }}&lt;/button&gt;<br>&lt;/form&gt;</pre><p><strong>Reactive Forms allow:</strong></p><ul><li>Centralized validation logic.</li><li>Easy switching between <strong>Add</strong> and <strong>Edit</strong> modes.</li><li>Reading values easily with this.countryForm.value.</li></ul><p>and also</p><p><strong>Reactive Forms Inside </strong><strong>&lt;app-delete-country&gt;</strong></p><pre>deleteForm = new FormGroup({<br>  confirm: new FormControl(&#39;&#39;, Validators.required)<br>});</pre><p>Component Reactive Form Type Purpose <strong>Main (Countries)</strong> FormControl Real-time search input <strong>Add/Edit Modal (</strong><strong>app-add-country)</strong> FormGroup + multiple FormControls To add or edit country details <strong>Delete Modal (</strong><strong>app-delete-country)</strong> (Optional) FormGroup for confirmation To confirm deletion</p><h3><strong>2. Template Driven Forms</strong></h3><p>Template-driven forms in Angular are a simple, HTML-centric way to build forms where most logic, including data binding and basic validation, resides directly in the template using directives like [(ngModel)] and *ngForm. They are ideal for simple forms with straightforward validation, offering quick development and a declarative style, but are less scalable for complex applications than reactive forms.</p><p>In a <strong>Template-Driven Form</strong>, most of the logic (binding, validation, etc.) is handled <strong>in the HTML template itself</strong> using Angular directives like:</p><ul><li>[(ngModel)] — for two-way data binding</li><li>#f=&quot;ngForm&quot; — for the form reference</li><li>#name=&quot;ngModel&quot; — to access form control states</li></ul><p>Here, Angular automatically <strong>creates the FormGroup and FormControl objects</strong> behind the scenes.<br> You don’t need to explicitly define them in TypeScript as in Reactive Forms.</p><p>for Example: Add Country (Template-Driven)</p><p>HTML — add-country.component.html</p><pre>&lt;form #countryForm=&quot;ngForm&quot; (ngSubmit)=&quot;onSubmit(countryForm)&quot;&gt;<br>  &lt;div&gt;<br>    &lt;label&gt;Country Code&lt;/label&gt;<br>    &lt;input<br>      type=&quot;text&quot;<br>      name=&quot;countryCode&quot;<br>      [(ngModel)]=&quot;country.countryCode&quot;<br>      required<br>      minlength=&quot;2&quot;<br>      #countryCode=&quot;ngModel&quot;<br>    /&gt;<br>    &lt;div *ngIf=&quot;countryCode.invalid &amp;&amp; countryCode.touched&quot; class=&quot;error&quot;&gt;<br>      Country Code is required and must be at least 2 characters.<br>    &lt;/div&gt;<br>  &lt;/div&gt;<br><br>  &lt;div&gt;<br>    &lt;label&gt;Country Name&lt;/label&gt;<br>    &lt;input<br>      type=&quot;text&quot;<br>      name=&quot;name&quot;<br>      [(ngModel)]=&quot;country.name&quot;<br>      required<br>      #name=&quot;ngModel&quot;<br>    /&gt;<br>    &lt;div *ngIf=&quot;name.invalid &amp;&amp; name.touched&quot; class=&quot;error&quot;&gt;<br>      Country Name is required.<br>    &lt;/div&gt;<br>  &lt;/div&gt;<br><br>  &lt;button type=&quot;submit&quot; [disabled]=&quot;countryForm.invalid&quot;&gt;Add Country&lt;/button&gt;<br>&lt;/form&gt;<br></pre><pre>import { Component } from &#39;@angular/core&#39;;<br><br>@Component({<br>  selector: &#39;app-add-country&#39;,<br>  templateUrl: &#39;./add-country.component.html&#39;,<br>  styleUrls: [&#39;./add-country.component.css&#39;]<br>})<br>export class AddCountryComponent {<br>  country = { countryCode: &#39;&#39;, name: &#39;&#39; };<br><br>  onSubmit(form: any) {<br>    if (form.valid) {<br>      console.log(&#39;Form Submitted:&#39;, this.country);<br>      alert(&#39;Country added successfully!&#39;);<br>      form.reset();<br>    }<br>  }<br>}</pre><pre>import { FormsModule } from &#39;@angular/forms&#39;;<br><br>@NgModule({<br>  imports: [<br>    BrowserModule,<br>    FormsModule  // required for template-driven forms<br>  ],<br>  ...<br>})<br>export class AppModule {}</pre><p>Feature Template-Driven Form Reactive Form Setup Simple, defined mostly in template Defined in TypeScript Form creation Implicit (ngForm, ngModel) Explicit (FormGroup, FormControl) Data binding Two-way ([(ngModel)]) One-way reactive streams Best for Small/simple forms Complex, dynamic, or large forms Validation Template-based Programmatic and reusable</p><h3>optional concept</h3><p><strong>synchronous access</strong></p><ul><li>Operations happen <strong>one after another</strong>.</li><li>Each line waits for the previous one to complete.</li><li>It can <strong>block the main thread</strong>, which is not ideal in frontend apps.</li></ul><p>-&gt;Here Reactive Forms Offer the core concept which is <strong>synchronous access</strong></p><p><strong>Asynchronous access</strong></p><ul><li>Operations run <strong>in the background</strong>.</li><li>The app doesn’t wait — it continues execution.</li><li>Commonly used with <strong>HTTP requests</strong>, <strong>file uploads</strong>, and <strong>observables</strong>.</li><li>&gt;Template-driven forms in Angular are asynchronous in nature</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8466ba1c67e2" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Building a Clean Search Functionality from a Table in Angular]]></title>
            <link>https://medium.com/@gnirujananthan/building-a-clean-search-functionality-in-angular-415fb13f84fa?source=rss-a5570e78fe53------2</link>
            <guid isPermaLink="false">https://medium.com/p/415fb13f84fa</guid>
            <dc:creator><![CDATA[GNirujananthan]]></dc:creator>
            <pubDate>Wed, 22 Oct 2025 05:38:08 GMT</pubDate>
            <atom:updated>2025-10-28T13:37:34.366Z</atom:updated>
            <content:encoded><![CDATA[<p>A search function is essential for improving user experience in modern web apps by assisting users in finding what they need fast. In this post, I’ll explain how I used Angular to create a straightforward and effective search function as part of a recent front-end project.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vNUr42TaWufIfZK-d60eNQ.jpeg" /><figcaption>search.png</figcaption></figure><h3>Implementing Reactive Search Functionality in season.component.html</h3><p><strong>for example search input code in season.component.html</strong></p><pre>&lt;div class=&quot;whole-btn-container&quot;&gt;<br> &lt;input<br> type=&quot;text&quot;<br> [formControl]=&quot;searchControl&quot;<br> placeholder=&quot;Search seasons…&quot;<br> class=&quot;border p-2 rounded w-full search-input&quot;<br> /&gt;<br>&lt;/div&gt;</pre><p><strong>Understanding the Search Input Code</strong></p><p>Let’s break down what’s happening in this simple yet powerful search input element:</p><ul><li><strong>[formControl]=&quot;searchControl&quot;</strong><br> This connects the input field to an Angular <strong>Reactive FormControl</strong> named searchControl.<br> It allows Angular to <strong>track changes</strong> in the input box dynamically — so every time the user types something, the valueChanges observable can react and trigger filtering logic.</li><li><strong>placeholder=&quot;Search seasons...&quot;</strong><br> This adds a <strong>helpful hint</strong> inside the input box, guiding users on what they can search for (in this case, seasons).</li><li><strong>class=&quot;border p-2 rounded w-full search-input&quot;</strong><br> These are <strong>Tailwind CSS utility classes</strong> (or your custom ones, depending on your setup) for styling:</li><li>border → adds a light border around the input</li><li>p-2 → gives padding for a comfortable input are</li><li>rounded → applies soft rounded corners</li><li>w-full → makes the input stretch across the container width</li><li>search-input → a custom class you can define for extra styles</li><li><strong>&lt;div class=&quot;whole-btn-container&quot;&gt;</strong><br> This div acts as a <strong>wrapper</strong> for layout and spacing — useful when you have additional buttons (like “Add” or “Filter”) alongside the search bar.</li></ul><p><strong>Summary</strong></p><p>This input field forms the UI entry point for your search functionality.<br> When combined with FormControl in your TypeScript file, it enables real-time, reactive searching — filtering your data list smoothly as users type.</p><h3>Implementing Reactive Search Functionality in season.component.ts</h3><p>In our Angular application, we wanted to add a <strong>real-time search feature</strong> to the Season Management module, allowing users to quickly find a season by name.<br> To achieve this, we implemented a <strong>reactive search system</strong> using Angular’s FormControl, ReactiveFormsModule, a reusable SearchUtilityService, and the SeasonService for backend integration.</p><p><strong>1.Importing Required Modules and Services</strong></p><pre>import { FormControl, ReactiveFormsModule } from &#39;@angular/forms&#39;;<br>import { SearchUtilityService } from &#39;../../../Service/search-utility.service&#39;;<br>import { SortableHeaderDirective } from &#39;../../../Directives/sortable-header.directive&#39;;</pre><ul><li><strong>FormControl</strong> – used to handle and track the value of our search input field in real time.</li><li><strong>ReactiveFormsModule</strong> – must be imported in the <strong>module file (</strong><strong>season.module.ts)</strong> to enable reactive form features in this component.</li><li><strong>SearchUtilityService</strong> – a custom service that handles debouncing and reactive stream logic for smooth searching.</li><li><strong>SortableHeaderDirective</strong> – enables table sorting (optional, but often used together with search for data tables).</li></ul><pre>import { ReactiveFormsModule } from &#39;@angular/forms&#39;;<br>@NgModule({<br> declarations: [SeasonComponent],<br> imports: [CommonModule, ReactiveFormsModule],<br>})<br>export class SeasonModule {}</pre><ul><li>Without this import, FormControl bindings in the template ([formControl]) will not work.</li></ul><p><strong>2. Declaring the Search Control</strong></p><pre> searchControl = new FormControl(&#39;&#39;);<br></pre><p>This line creates a new <strong>reactive form control</strong> instance.<br> It’s bound to the search input field and emits a new value every time the user types — which we’ll use to trigger live filtering.</p><p>3. Injecting the Utility Service</p><pre>constructor(private searchUtil: SearchUtilityService) {}</pre><p>The SearchUtilityService is injected through the constructor.<br> It provides a method called createSearchPipeline() that helps manage the flow of search input values efficiently (with debounce and switchMap).</p><p>4. Initializing the Search Listener</p><pre>ngOnInit(): void {<br>  this._searchUtility();<br>}</pre><p>5.Implementing the Reactive Search Logic</p><pre>private _searchUtility() {<br>  this.subscription = this.searchControl.valueChanges<br>    .pipe(<br>      this.searchUtil.createSearchPipeline((query) =&gt;<br>        query<br>          ? this.seasonService.getAllSeasonsBySearch(query)<br>          : this.seasonService.getAllSeasons()<br>      )<br>    )<br>    .subscribe((res) =&gt; {<br>      this.seasons = res;<br>      this.currentPage = 1;<br>    });<br>}</pre><p>Let’s break down what happens here:</p><ul><li><strong>valueChanges</strong> — emits every time the user types in the input field.</li><li><strong>createSearchPipeline()</strong> — applies operators like debounceTime, distinctUntilChanged, and switchMap to control API calls efficiently.</li><li><strong>Conditional logic:</strong></li><li>If a query exists → it calls getAllSeasonsBySearch(query) to fetch filtered results.</li><li>If the input is empty → it calls getAllSeasons() to reload all data.</li><li><strong>Subscription:</strong> updates the seasons list and resets pagination to the first page.</li></ul><p>6. Backend Search Implementation (season.service.ts)</p><pre>public getAllSeasonsBySearch(name: string) {<br>  return this.http<br>    .get&lt;SeasonResponseData&gt;(<br>      this.baseUrl + `master-data/season/name-search/search?name=${name}`<br>    )<br>    .pipe(<br>      map((res: any) =&gt; {<br>        if (res.result &amp;&amp; Array.isArray(res.result)) {<br>          return res.result.map(<br>            (season: any) =&gt; new SeasonResponseData(season)<br>          );<br>        } else {<br>          return [];<br>        }<br>      })<br>    );<br>}</pre><p>Here’s what’s happening:</p><ul><li>The name query parameter is used to send a GET request to the backend.</li><li>RxJS map() is used to process the response, turning the result array into a list of SeasonResponseData objects.</li><li>The API safely returns an empty array in the event that it receives no response or an invalid structure.</li></ul><h3>Final Outcome</h3><p>With this setup:</p><ul><li>The <strong>Reactive FormControl</strong> listens to the input box in real time.</li><li>The <strong>SearchUtilityService</strong> optimizes and manages the search stream.</li><li>The <strong>SeasonService</strong> communicates with the backend to fetch matching data.</li></ul><p>The result is a <strong>smooth, responsive, and scalable</strong> search experience in your Angular application.</p><h3>Key Benefits</h3><p><strong>Reactive and real-time search experience</strong><br><strong>Reduced API load</strong> with debouncing and stream handling<br><strong>Reusable logic</strong> — the same utility can be used across multiple modules<br><strong>Clean separation</strong> of concerns (UI, logic, and data access)</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=415fb13f84fa" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>