<?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 Rajkamal MM on Medium]]></title>
        <description><![CDATA[Stories by Rajkamal MM on Medium]]></description>
        <link>https://medium.com/@raj1996kamal?source=rss-accb4f6b70be------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/2*uaAMchSENG90WF8U02TzSg.jpeg</url>
            <title>Stories by Rajkamal MM on Medium</title>
            <link>https://medium.com/@raj1996kamal?source=rss-accb4f6b70be------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 05 Dec 2026 22:39:05 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@raj1996kamal/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[Understanding Signal Forms in Angular]]></title>
            <link>https://medium.com/@raj1996kamal/understanding-signal-forms-in-angular-e890c0d29817?source=rss-accb4f6b70be------2</link>
            <guid isPermaLink="false">https://medium.com/p/e890c0d29817</guid>
            <category><![CDATA[angular]]></category>
            <category><![CDATA[angular-learning]]></category>
            <category><![CDATA[angular-app-development]]></category>
            <category><![CDATA[angular-signals]]></category>
            <category><![CDATA[signal-forms]]></category>
            <dc:creator><![CDATA[Rajkamal MM]]></dc:creator>
            <pubDate>Mon, 13 Oct 2025 03:19:07 GMT</pubDate>
            <atom:updated>2025-10-13T03:19:07.534Z</atom:updated>
            <content:encoded><![CDATA[<p>“Signal forms” is a feature in the Angular framework that uses signals to manage and track the state of forms. Introduced as an experimental feature in Angular v21, this approach offers a simpler, more reactive, and type-safe way to build forms compared to the traditional reactive or template-driven forms. The feature was merged into the main development branch of the Angular framework in September 2025.</p><p>The core idea is to establish a direct, reactive link between your form’s data model and the form controls in your template. When a signal in your model changes, the corresponding form field is automatically updated, and vice versa.</p><p>How signal forms work</p><p>The signal forms API simplifies form management through a few key concepts:</p><ul><li><strong>Data model as a signal</strong>: The source of truth for your form is a signal that holds an object representing the form’s data. This model is defined once and is fully type-safe.</li><li><strong>form() function</strong>: You use the form() function to transform your signal model into a tracked form structure.</li><li><strong>[control] directive</strong>: In the template, you use the [control] directive to bind HTML input elements directly to the fields on your form object. This replaces the need for formControlName.</li><li><strong>Reactive status</strong>: The form and its controls expose signals for their state, such as valid, touched, dirty, and errors. You can read these signals to display validation messages or change the UI.</li><li><strong>Declarative validation</strong>: Validation rules are defined declaratively when creating the form, instead of being applied imperatively to each FormControl.</li></ul><p>Key benefits</p><ul><li><strong>Less boilerplate</strong>: There is no need to manually create FormGroup or FormControl instances. The form structure is inferred from your signal-based data model.</li><li><strong>Improved reactivity</strong>: Signals offer a more precise, fine-grained reactivity model than Zone.js, meaning only the necessary parts of your application are updated when data changes.</li><li><strong>Better type safety</strong>: Because the form is derived from a type-safe signal model, you get full type checking for your form’s data.</li><li><strong>Simplified state management</strong>: Complex tasks like conditional validation and handling submissions are simpler due to the reactive nature of signals.</li></ul><p>Example code: A simple login form</p><p>The following example demonstrates building a login form using the experimental signal forms API.</p><p><strong>1. Define the component (</strong><strong>login.component.ts)</strong></p><p>First, you define your data model as a signal. Then, you use the form() function to create the reactive form instance.</p><pre>import { Component, signal } from &#39;@angular/core&#39;;<br>import { form, required } from &#39;@angular/forms/signals&#39;;<br>import { CommonModule } from &#39;@angular/common&#39;;<br><br>@Component({<br>  selector: &#39;app-login&#39;,<br>  standalone: true,<br>  imports: [CommonModule],<br>  templateUrl: &#39;./login.component.html&#39;,<br>})<br>export class LoginComponent {<br>  // 1. Define the data model as a signal<br>  readonly loginModel = signal({<br>    username: &#39;&#39;,<br>    password: &#39;&#39;,<br>  });<br><br>  // 2. Create the signal form, including validation<br>  readonly loginForm = form(this.loginModel, (path) =&gt; [<br>    required(path.username, { message: &#39;Username is required&#39; }),<br>    required(path.password, { message: &#39;Password is required&#39; }),<br>  ]);<br><br>  submitForm(): void {<br>    // Check if the form is valid before processing<br>    if (this.loginForm.valid()) {<br>      console.log(&#39;Login data:&#39;, this.loginModel());<br>      alert(&#39;Form submitted successfully!&#39;);<br>    } else {<br>      alert(&#39;Form is invalid. Please check the fields.&#39;);<br>    }<br>  }<br>}</pre><p><strong>2. Create the component template (</strong><strong>login.component.html)</strong></p><p>The template uses the [control] directive to bind inputs directly to the form&#39;s fields. An @for loop can iterate over any validation errors to display a message.</p><pre>&lt;form (submit)=&quot;submitForm(); $event.preventDefault()&quot;&gt;<br>  &lt;div&gt;<br>    &lt;label&gt;Username&lt;/label&gt;<br>    &lt;input type=&quot;text&quot; [control]=&quot;loginForm.username&quot; /&gt;<br>    &lt;!-- Display errors using the form&#39;s state signals --&gt;<br>    @if (loginForm.username.touched() &amp;&amp; loginForm.username.invalid()) {<br>      @for (error of loginForm.username.errors(); track error.kind) {<br>        &lt;p class=&quot;validation-error&quot;&gt;{{ error.message }}&lt;/p&gt;<br>      }<br>    }<br>  &lt;/div&gt;<br><br>  &lt;div&gt;<br>    &lt;label&gt;Password&lt;/label&gt;<br>    &lt;input type=&quot;password&quot; [control]=&quot;loginForm.password&quot; /&gt;<br>    @if (loginForm.password.touched() &amp;&amp; loginForm.password.invalid()) {<br>      @for (error of loginForm.password.errors(); track error.kind) {<br>        &lt;p class=&quot;validation-error&quot;&gt;{{ error.message }}&lt;/p&gt;<br>      }<br>    }<br>  &lt;/div&gt;<br><br>  &lt;button type=&quot;submit&quot; [disabled]=&quot;!loginForm.valid()&quot;&gt;Login&lt;/button&gt;<br>&lt;/form&gt;<br><br>&lt;style&gt;<br>  .validation-error {<br>    color: red;<br>    font-size: 0.8em;<br>  }<br>&lt;/style&gt;</pre><p><strong>3. Run the application</strong></p><p>To use signal forms, you must be using a compatible version of Angular (v21+ at the time of writing). The signal forms API is experimental and subject to change, but its advantages in developer experience and performance make it a valuable area of future development.</p><p>Reference Link : <a href="https://angular.dev/guide/signals">https://angular.dev/guide/signals</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e890c0d29817" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Hydration in Angular]]></title>
            <link>https://medium.com/@raj1996kamal/hydration-in-angular-9820e697645b?source=rss-accb4f6b70be------2</link>
            <guid isPermaLink="false">https://medium.com/p/9820e697645b</guid>
            <category><![CDATA[angular]]></category>
            <category><![CDATA[angular-server-side]]></category>
            <category><![CDATA[hydration]]></category>
            <category><![CDATA[angular-hydration]]></category>
            <category><![CDATA[angular-ssr]]></category>
            <dc:creator><![CDATA[Rajkamal MM]]></dc:creator>
            <pubDate>Fri, 10 Oct 2025 06:32:15 GMT</pubDate>
            <atom:updated>2025-10-10T07:27:07.132Z</atom:updated>
            <content:encoded><![CDATA[<p>When you use Server-Side Rendering (SSR), the server sends a fully printed, but static, HTML page to your browser. Hydration is the process where Angular arrives, looks at the static HTML, and quickly attaches all the dynamic behavior — like buttons, form fields, and animations — to it, without throwing away the beautiful static page.</p><p>In short:</p><ul><li><strong>Without hydration:</strong> The server sends a static page. Angular then downloads, deletes the static content, and rebuilds everything from scratch on the client to make it interactive.</li><li><strong>With hydration:</strong> The server sends a static page. Angular downloads, notices the static content is already there, and simply reuses it, adding only the necessary interactive behavior.</li></ul><p>Example code with hydration</p><p>To use hydration, you first need to have an Angular application set up with Server-Side Rendering (SSR). If you create a new Angular project with the --ssr flag, hydration is enabled automatically.</p><p><strong>Enable hydration in your main configuration</strong></p><p>In your app.config.ts, you provide the client hydration feature.</p><pre><br>// src/app/app.config.ts<br>import { ApplicationConfig } from &#39;@angular/core&#39;;<br>import { provideClientHydration } from &#39;@angular/platform-browser&#39;;<br>import { provideRouter } from &#39;@angular/router&#39;;<br><br>import { routes } from &#39;./app.routes&#39;;<br><br>export const appConfig: ApplicationConfig = {<br>  providers: [<br>    provideRouter(routes),<br>    // This is the line that enables hydration.<br>    provideClientHydration()<br>  ]<br>};</pre><p><strong>Create an interactive component</strong></p><p>Here is a simple button component that needs to be interactive.</p><pre>// src/app/counter-button/counter-button.component.ts<br>import { Component, signal } from &#39;@angular/core&#39;;<br><br>@Component({<br>  selector: &#39;app-counter-button&#39;,<br>  standalone: true,<br>  template: `<br>    &lt;button (click)=&quot;increment()&quot;&gt;<br>      Click count: {{ count() }}<br>    &lt;/button&gt;<br>  `,<br>  styles: `button { padding: 10px; font-size: 16px; }`<br>})<br>export class CounterButtonComponent {<br>  count = signal(0);<br><br>  increment() {<br>    this.count.update(value =&gt; value + 1);<br>  }<br>}</pre><p><strong>Use the component in your app</strong></p><p>When you build your app for SSR, the &lt;app-counter-button&gt; HTML is pre-rendered on the server. When the page loads in the browser, hydration makes the button clickable without rebuilding it.</p><pre>&lt;!-- src/app/app.component.html --&gt;<br>&lt;h1&gt;Welcome to my Hydrated App!&lt;/h1&gt;<br>&lt;p&gt;This button becomes interactive instantly, without flashing.&lt;/p&gt;<br>&lt;app-counter-button /&gt;</pre><p>What happens if we don’t use hydration?</p><p>If you don’t use hydration (or, more accurately, if you skip it for a specific component), Angular behaves like older SSR applications. The process is:</p><ol><li><strong>Fast static display:</strong> The server sends the HTML, and the user sees the content immediately.</li><li><strong>Destruction and rebuilding:</strong> Angular’s JavaScript arrives, removes the server-rendered DOM (the button from the server), and then builds a brand-new one from scratch.</li><li><strong>Visible flicker:</strong> The user may see a brief flicker as the button disappears and reappears, which provides a poor user experience.</li><li><strong>Lost interactions:</strong> If the user clicks the button before it’s re-rendered by the client, the click won’t register.</li></ol><p>Example code without hydration</p><p>You can intentionally skip hydration for a component by using the ngSkipHydration host binding.</p><p><strong>1. Update the interactive component</strong></p><p>Add the host: { ngSkipHydration: &#39;true&#39; } property to your component&#39;s decorator.</p><pre>// src/app/counter-button/counter-button.component.ts<br>import { Component, signal } from &#39;@angular/core&#39;;<br><br>@Component({<br>  selector: &#39;app-counter-button&#39;,<br>  standalone: true,<br>  // This tells Angular to skip hydration for this component.<br>  host: { &#39;ngSkipHydration&#39;: &#39;true&#39; },<br>  template: `<br>    &lt;button (click)=&quot;increment()&quot;&gt;<br>      Click count: {{ count() }}<br>    &lt;/button&gt;<br>  `,<br>  styles: `button { padding: 10px; font-size: 16px; }`<br>})<br>export class CounterButtonComponent {<br>  count = signal(0);<br><br>  increment() {<br>    this.count.update(value =&gt; value + 1);<br>  }<br>}</pre><p><strong>The app’s behavior</strong></p><p>Even though the server-side rendering will still output the HTML for the button, the ngSkipHydration flag ensures that the client-side Angular code will not reuse it. Instead, it will remove it and insert a new version, causing a visible delay and a flash of unstyled content.</p><p><strong>Reference</strong>: <a href="https://angular.dev/guide/hydration">https://angular.dev/guide/hydration</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9820e697645b" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Understanding Signal API in Angular]]></title>
            <link>https://medium.com/@raj1996kamal/understanding-signal-api-in-angular-de6658992aa9?source=rss-accb4f6b70be------2</link>
            <guid isPermaLink="false">https://medium.com/p/de6658992aa9</guid>
            <category><![CDATA[angular-learning]]></category>
            <category><![CDATA[angular]]></category>
            <category><![CDATA[signal]]></category>
            <category><![CDATA[angular-signals]]></category>
            <category><![CDATA[angular-state-management]]></category>
            <dc:creator><![CDATA[Rajkamal MM]]></dc:creator>
            <pubDate>Wed, 01 Oct 2025 05:21:52 GMT</pubDate>
            <atom:updated>2025-10-01T05:22:38.081Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*YYFQTrQ4SmDme5HX52KD0w.png" /></figure><p><strong>A signal API is a system that holds a value and notifies interested consumers when that value changes</strong>. Instead of directly storing and mutating a variable, you wrap the value in a signal, which allows a framework like Angular to automatically track its dependencies and update anything that relies on it. This creates a fine-grained, reactive data flow, improving application performance.</p><h3><strong>toSignal</strong></h3><p>The toSignal() function converts an RxJS Observable into a reactive Signal. This is especially useful for integrating asynchronous data sources, like an HTTP request, with Angular&#39;s signal-based reactivity.</p><p><strong>Simple words</strong></p><p>Think of toSignal as a one-way bridge from the world of asynchronous &quot;streams&quot; (Observables) to the synchronous world of Signals. It subscribes to an Observable and, each time the Observable emits a new value, it updates the signal.</p><p><strong>Example</strong></p><p>Imagine you are fetching user data from an API and want to display it in a component.</p><pre>// service.ts<br>import { HttpClient } from &#39;@angular/common/http&#39;;<br>import { toSignal } from &#39;@angular/core/rxjs-interop&#39;;<br>import { Injectable } from &#39;@angular/core&#39;;<br><br>@Injectable({ providedIn: &#39;root&#39; })<br>export class UserService {<br>  constructor(private http: HttpClient) {}<br><br>  getUserData(userId: number) {<br>    // Returns an Observable of user data<br>    return this.http.get&lt;{ name: string }&gt;(`https://api.example.com/users/${userId}`);<br>  }<br>}<br><br>// component.ts<br>import { Component, inject } from &#39;@angular/core&#39;;<br>import { toSignal } from &#39;@angular/core/rxjs-interop&#39;;<br>import { UserService } from &#39;./user.service&#39;;<br><br>@Component({<br>  standalone: true,<br>  selector: &#39;app-user-profile&#39;,<br>  template: `<br>    @if (user()) {<br>      &lt;h1&gt;Hello, {{ user()?.name }}&lt;/h1&gt;<br>    } @else {<br>      &lt;p&gt;Loading user...&lt;/p&gt;<br>    }<br>  `,<br>})<br>export class UserProfileComponent {<br>  private userService = inject(UserService);<br><br>  // Convert the Observable to a signal with a null initial value<br>  user = toSignal(this.userService.getUserData(1), { initialValue: null });<br>}</pre><ul><li>toSignal handles the subscription to the Observable and automatically updates the user signal.</li><li>The template reads the user() signal and updates automatically when the data arrives.</li></ul><h3><strong>linkedSignal</strong></h3><p>The linkedSignal() function creates a writable signal that is automatically updated based on the value of one or more source signals. It provides the flexibility of a regular signal while maintaining a reactive link to its dependencies.</p><p><strong>Simple words</strong></p><p>A linkedSignal is like a superpowered computed signal. It gets its initial value by calculating it from other signals, but you can also manually change its value at any time. When a source signal changes, the linkedSignal automatically re-calculates, potentially overwriting any manual changes.</p><p><strong>Example</strong></p><p>A shopping cart component where the quantity input resets to the product’s default value whenever the selected product changes, but the user can still manually adjust the quantity.</p><pre>// component.ts<br>import { Component, signal, linkedSignal } from &#39;@angular/core&#39;;<br><br>@Component({<br>  standalone: true,<br>  selector: &#39;app-shopping-cart&#39;,<br>  template: `<br>    &lt;p&gt;Product: {{ selectedProduct().name }}&lt;/p&gt;<br>    &lt;p&gt;Quantity: &lt;input type=&quot;number&quot; [(ngModel)]=&quot;quantity&quot; /&gt;&lt;/p&gt;<br>  `,<br>})<br>export class ShoppingCartComponent {<br>  // Writable signal for the selected product<br>  selectedProduct = signal({ name: &#39;T-Shirt&#39;, defaultQuantity: 1 });<br><br>  // A linked signal for the quantity<br>  quantity = linkedSignal({<br>    source: () =&gt; this.selectedProduct(),<br>    compute: (product) =&gt; product.defaultQuantity,<br>  });<br><br>  changeProduct() {<br>    this.selectedProduct.set({ name: &#39;Jeans&#39;, defaultQuantity: 2 });<br>  }<br><br>  constructor() {<br>    // Triggering a product change will cause &#39;quantity&#39; to re-compute<br>    this.changeProduct();<br>    // Later, the user can manually change the quantity to 5<br>    // But if selectedProduct changes again, this manual change is overwritten<br>    this.quantity.set(5);<br>  }<br>}</pre><ul><li>The quantity is linked to selectedProduct. When selectedProduct changes, the quantity resets.</li><li>Unlike a computed signal, linkedSignal is writable, allowing for user interaction.</li></ul><h3><strong>effect</strong></h3><p>An effect() is a function that runs automatically whenever one or more signals that it reads change their value. It&#39;s designed for handling side effects that need to react to state changes without producing a new signal.</p><p><strong>Simple words</strong></p><p>An effect is an automatic, background watcher for your signals. It&#39;s the place you put code that needs to react to a signal&#39;s change, like logging something, saving data to local storage, or interacting with an external API. An effect does not return a value.</p><p><strong>Example</strong></p><p>An effect to automatically save a user’s theme preference to local storage whenever it changes.</p><pre>// component.ts<br>import { Component, signal, effect } from &#39;@angular/core&#39;;<br><br>@Component({<br>  standalone: true,<br>  selector: &#39;app-theme-selector&#39;,<br>  template: `<br>    &lt;button (click)=&quot;toggleTheme()&quot;&gt;Toggle Theme&lt;/button&gt;<br>  `,<br>})<br>export class ThemeSelectorComponent {<br>  theme = signal(&#39;light&#39;);<br><br>  constructor() {<br>    // The effect runs initially and whenever the `theme` signal changes<br>    effect(() =&gt; {<br>      const currentTheme = this.theme();<br>      console.log(`The theme has changed to: ${currentTheme}`);<br>      localStorage.setItem(&#39;theme&#39;, currentTheme);<br>    });<br>  }<br><br>  toggleTheme() {<br>    this.theme.update((currentTheme) =&gt;<br>      currentTheme === &#39;light&#39; ? &#39;dark&#39; : &#39;light&#39;<br>    );<br>  }<br>}</pre><ul><li>The effect automatically tracks the theme() signal.</li><li>Every time the theme signal is updated (via set or update), the effect&#39;s callback function runs again.</li><li>The code inside the effect is a &quot;side effect&quot; because it interacts with the outside world (the browser&#39;s localStorage) instead of just calculating a new value for a signal.</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=de6658992aa9" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Understanding Life Cycle hooks in Angular]]></title>
            <link>https://medium.com/@raj1996kamal/understanding-life-cycle-hooks-in-angular-d65264269271?source=rss-accb4f6b70be------2</link>
            <guid isPermaLink="false">https://medium.com/p/d65264269271</guid>
            <category><![CDATA[angular-lifecycle-hooks]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[deep-learning]]></category>
            <category><![CDATA[angular-lifecycle]]></category>
            <category><![CDATA[angular]]></category>
            <dc:creator><![CDATA[Rajkamal MM]]></dc:creator>
            <pubDate>Mon, 15 Sep 2025 08:08:36 GMT</pubDate>
            <atom:updated>2025-09-15T08:56:28.577Z</atom:updated>
            <content:encoded><![CDATA[<p>Angular lifecycle hooks are special methods that get called at specific moments in a component’s existence. They help you add custom behavior during different phases like creation, change detection, and destruction of components. Here’s an easy-to-understand overview of the main lifecycle hooks:</p><h3>1. ngOnChanges</h3><ul><li><strong>When it runs:</strong> Right after a data-bound input property changes in a component (including the first time).</li><li><strong>What it means:</strong> If your component receives new input values from its parent, this method notices those changes so you can act on them.</li><li><strong>Use case:</strong> React to changes in input properties.</li></ul><h3>2. ngOnInit</h3><ul><li><strong>When it runs:</strong> Once, right after the first ngOnChanges (if any), when the component is initialized.</li><li><strong>What it means:</strong> This is when your component is ready, but the view is not yet fully rendered.</li><li><strong>Use case:</strong> Initialization logic like fetching data or setting up default states.</li></ul><h3>3. ngDoCheck</h3><ul><li><strong>When it runs:</strong> During every change detection run, which can happen many times.</li><li><strong>What it means:</strong> It lets you write your own custom change detection. Angular’s default change detection might not catch everything, so this is a manual hook.</li><li><strong>Use case:</strong> Detecting and acting on changes Angular might miss.</li></ul><h3>4. ngAfterContentInit</h3><ul><li><strong>When it runs:</strong> Once, after Angular projects external content into the component (via &lt;ng-content&gt;).</li><li><strong>What it means:</strong> Your projected content is ready now.</li><li><strong>Use case:</strong> Initialization based on projected content.</li></ul><h3>5. ngAfterContentChecked</h3><ul><li><strong>When it runs:</strong> After every check of the projected content.</li><li><strong>What it means:</strong> It lets you respond after the projected content changes are checked.</li><li><strong>Use case:</strong> Fix or update things related to projected content.</li></ul><h3>6. ngAfterViewInit</h3><ul><li><strong>When it runs:</strong> Once after Angular initializes the component’s views and child views.</li><li><strong>What it means:</strong> The component’s template and all its child components’ templates are fully rendered.</li><li><strong>Use case:</strong> Access child components or manipulate the DOM.</li></ul><h3>7. ngAfterViewChecked</h3><ul><li><strong>When it runs:</strong> After every check of the component’s views and child views.</li><li><strong>What it means:</strong> Allows you to react when Angular completes checking views.</li><li><strong>Use case:</strong> Post-processing or cleanup after view updates.</li></ul><h3>8. ngOnDestroy</h3><ul><li><strong>When it runs:</strong> Right before the component is destroyed and removed from the DOM.</li><li><strong>What it means:</strong> Time to clean up resources like event listeners, timers, or subscriptions.</li><li><strong>Use case:</strong> Avoid memory leaks by cleaning up.</li></ul><h3>Summary Table</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*t3BuclyGMK8rsZK_-f88hQ.png" /></figure><ul><li><strong>Initialization</strong>: Use <strong><em>ngOnInit</em></strong> to fetch data or set up initial state.</li><li><strong>Change Detection</strong>: Use <strong><em>ngOnChanges</em></strong> or <strong><em>ngDoCheck</em></strong><em> </em>to respond to data changes.</li><li><strong>Content Projection</strong>: Use <strong><em>ngAfterContentInit</em></strong> and <strong><em>ngAfterContentChecked</em></strong> to manage projected content.</li><li><strong>View Manipulation</strong>: Use <strong><em>ngAfterViewInit</em></strong> and <strong><em>ngAfterViewChecked</em></strong><em> </em>to interact with the component&#39;s view.</li><li><strong>Cleanup</strong>: Use <strong><em>ngOnDestroy</em></strong> to release resources and avoid memory leaks.</li></ul><p>Understanding these hooks helps you better manage your Angular component’s behavior throughout its life and build more efficient and bug-free apps.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d65264269271" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Understanding Angular Route Guards]]></title>
            <link>https://medium.com/@raj1996kamal/understanding-angular-route-guards-829d8906c79c?source=rss-accb4f6b70be------2</link>
            <guid isPermaLink="false">https://medium.com/p/829d8906c79c</guid>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[route-guards]]></category>
            <category><![CDATA[web-technology]]></category>
            <category><![CDATA[angular]]></category>
            <category><![CDATA[angular-router-guard]]></category>
            <dc:creator><![CDATA[Rajkamal MM]]></dc:creator>
            <pubDate>Fri, 12 Sep 2025 03:01:51 GMT</pubDate>
            <atom:updated>2025-09-12T03:01:51.992Z</atom:updated>
            <content:encoded><![CDATA[<p>Route guards in Angular are special services that act as gatekeepers for your application’s routes. They check for certain conditions before allowing, canceling, or redirecting navigation. This provides a powerful way to manage access, protect sensitive data, and improve the user experience.</p><h3><strong>CanActivate</strong></h3><p>This guard determines if a user can activate (enter) a route. It is most commonly used for authentication checks.</p><ul><li><strong>Simple explanation:</strong> Can this user go to this page?</li></ul><p><strong>Example:</strong> An AuthGuard checks if a user is logged in before they can access the dashboard.</p><p>Guard service (auth.guard.ts):</p><pre>import { Injectable } from &#39;@angular/core&#39;; <br>import { CanActivate, Router, UrlTree } from &#39;@angular/router&#39;; <br>import { Observable } from &#39;rxjs&#39;; <br>import { AuthService } from &#39;./auth.service&#39;; // Assume this service exists <br> <br>@Injectable({ providedIn: &#39;root&#39; }) <br>export class AuthGuard implements CanActivate { <br> constructor(private authService: AuthService, private router: Router) {} <br> <br> canActivate(): Observable&lt;boolean | UrlTree&gt; | Promise&lt;boolean | UrlTree&gt; | boolean | UrlTree { <br> if (this.authService.isLoggedIn()) { <br> return true; <br> } <br> // Not logged in, redirect to the login page <br> return this.router.createUrlTree([&#39;/login&#39;]); <br> } <br>}</pre><ul><li>Route configuration (app-routing.module.ts):</li></ul><pre>const routes: Routes = [ <br> { path: &#39;login&#39;, component: LoginComponent }, <br> { path: &#39;dashboard&#39;, component: DashboardComponent, canActivate: [AuthGuard] }, <br>t <br>];</pre><h3><strong>CanDeactivate</strong></h3><p>This guard determines if a user can deactivate (leave) a route. It’s often used to prevent accidental data loss by prompting users about unsaved changes.</p><ul><li><strong>Simple explanation:</strong> Is the user allowed to leave this page?</li><li><strong>Example: </strong>A CanDeactivateGuard prevents a user from navigating away from a form until they save their changes or confirm they want to discard them.</li><li>Guard service (unsaved-changes.guard.ts):</li></ul><pre>import { CanDeactivate } from &#39;@angular/router&#39;; <br>import { Observable } from &#39;rxjs&#39;; <br> <br>export interface CanComponentDeactivate { <br> canDeactivate: () =&gt; Observable&lt;boolean&gt; | Promise&lt;boolean&gt; | boolean; <br>} <br> <br>export const unsavedChangesGuard: CanDeactivate&lt;CanComponentDeactivate&gt; = (component) =&gt; { <br> return component.canDeactivate ? component.canDeactivate() : true; <br>};</pre><p>Route configuration (app-routing.module.ts):</p><pre>const routes: Routes = [ <br> { <br> path: &#39;profile-editor&#39;, <br> component: ProfileEditorComponent, <br> canDeactivate: [unsavedChangesGuard] <br> }, <br>];</pre><p>Component (profile-editor.component.ts):</p><pre>import { Component } from &#39;@angular/core&#39;; <br>import { CanComponentDeactivate } from &#39;./unsaved-changes.guard&#39;; <br> <br>@Component({ /* … */ }) <br>export class ProfileEditorComponent implements CanComponentDeactivate { <br> hasChanges = false; <br> <br> canDeactivate(): boolean { <br> if (this.hasChanges) { <br> return confirm(&#39;You have unsaved changes. Do you really want to leave?&#39;); <br> } <br> return true; <br> } <br>}</pre><h3><strong>CanMatch</strong></h3><p>This guard determines if a route should be considered a potential match for a given URL. Introduced in Angular v14, it allows for more flexible routing rules than CanActivate.</p><ul><li><strong>Simple explanation:</strong> Does this route match the URL based on certain conditions? If not, ignore this route and check the next one.</li><li><strong>Example:</strong> Display different components for the same /products URL based on the user’s role.</li><li>Route configuration (app-routing.module.ts):</li></ul><pre>const routes: Routes = [ <br> { <br> path: &#39;products&#39;, <br> loadComponent: () =&gt; import(&#39;./consumer-products/consumer-products.component&#39;), <br> canMatch: [() =&gt; inject(AuthService).getRole() === &#39;customer&#39;] <br> }, <br> { <br> path: &#39;products&#39;, <br> loadComponent: () =&gt; import(&#39;./industrial-products/industrial-products.component&#39;), <br> canMatch: [() =&gt; inject(AuthService).getRole() === &#39;industrial&#39;] <br> }, <br> // … <br>];</pre><h3><strong>Resolve</strong></h3><p>This guard fetches data <em>before</em> a route is activated, ensuring that a component has the data it needs from the start.</p><ul><li><strong>Simple explanation:</strong> Fetch the data needed for a page before showing it.</li><li><strong>Example: </strong>Fetch a user’s details from an API before loading the UserDetailsComponent.</li><li>Guard service (user-details.resolver.ts):</li></ul><pre>import { inject } from &#39;@angular/core&#39;; <br>import { ResolveFn } from &#39;@angular/router&#39;; <br>import { UserService } from &#39;./user.service&#39;; // Assume this service exists <br> <br>export const userDetailsResolver: ResolveFn&lt;User&gt; = (route) =&gt; { <br> const userId = route.paramMap.get(&#39;id&#39;)!; <br> return inject(UserService).getUser(userId); <br>};</pre><p>Route configuration (app-routing.module.ts):</p><pre>const routes: Routes = [ <br> { <br> path: &#39;users/:id&#39;, <br> component: UserDetailsComponent, <br> resolve: { <br> user: userDetailsResolver <br> } <br> }, <br> // … <br>];</pre><p>Component (user-details.component.ts):</p><pre>import { Component, OnInit } from &#39;@angular/core&#39;; <br>import { ActivatedRoute } from &#39;@angular/router&#39;; <br> <br>@Component({ /* … */ }) <br>export class UserDetailsComponent implements OnInit { <br> user: User | undefined; <br> <br> constructor(private activatedRoute: ActivatedRoute) {} <br> <br> ngOnInit(): void { <br> // The data is available synchronously because the resolver waited for it <br> this.activatedRoute.data.subscribe(({ user }) =&gt; { <br> this.user = user; <br> }); <br> } <br>}</pre><h3><strong>CanLoad (Legacy)</strong></h3><p>This guard prevents an entire lazy-loaded module from being loaded if the user doesn’t have permission. It prevents the module’s code from even being downloaded by the browser.</p><ul><li><strong>Simple explanation:</strong> Don’t download this lazy-loaded module unless the user has permission.</li><li><strong>Example:</strong> Prevent non-admin users from downloading the code for the AdminModule when they attempt to navigate to /admin.</li><li>Route configuration (app-routing.module.ts):</li></ul><pre>typescript<br>const routes: Routes = [ <br> { <br> path: &#39;admin&#39;, <br> loadChildren: () =&gt; import(&#39;./admin/admin.module&#39;).then(m =&gt; m.AdminModule), <br> canLoad: [adminGuard] <br> }, <br> // … <br>];</pre><ul><li>Note: CanLoad has been largely superseded by CanMatch and is now considered a legacy guard. CanMatch offers a more powerful solution to the same problem by allowing a match to be skipped without canceling navigation altogether.</li></ul><h3><strong>CanActivateChild</strong></h3><p>This guard functions identically to CanActivate, but it is applied to a parent route and protects all its child routes.</p><ul><li><strong>Simple explanation: </strong>Apply a single guard to protect all child pages of a parent route.</li><li><strong>Example:</strong> A parent dashboard route with multiple child routes (/dashboard/stats, /dashboard/settings). A CanActivateChild guard on the parent route will protect all the child routes without having to add CanActivate to each one.</li><li>Route configuration (app-routing.module.ts):</li></ul><pre>const routes: Routes = [ <br> { <br> path: &#39;dashboard&#39;, <br> canActivateChild: [AuthGuard], // Protects all child routes <br> children: [ <br> { path: &#39;stats&#39;, component: StatsComponent }, <br> { path: &#39;settings&#39;, component: SettingsComponent } <br> ] <br> }, <br> // … <br>];</pre><blockquote>REFERENCE LINKS:</blockquote><p><a href="https://angular.dev/guide/routing/route-guards">Angular</a></p><p><a href="https://www.udemy.com/course/the-complete-guide-to-angular-2/">https://www.udemy.com/course/the-complete-guide-to-angular-2/</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=829d8906c79c" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Understanding Pre-Loading strategies in angular]]></title>
            <link>https://medium.com/@raj1996kamal/understanding-pre-loading-strategies-in-angular-4f9a783bfe3c?source=rss-accb4f6b70be------2</link>
            <guid isPermaLink="false">https://medium.com/p/4f9a783bfe3c</guid>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[front-end-development]]></category>
            <category><![CDATA[information-technology]]></category>
            <category><![CDATA[angular]]></category>
            <category><![CDATA[preloading-strategy]]></category>
            <dc:creator><![CDATA[Rajkamal MM]]></dc:creator>
            <pubDate>Thu, 11 Sep 2025 15:44:57 GMT</pubDate>
            <atom:updated>2025-09-11T15:44:57.110Z</atom:updated>
            <content:encoded><![CDATA[<p>Preloading strategies are techniques used in Angular to load lazy-loaded modules in the background, after the main application has loaded. This makes subsequent navigation to those lazy-loaded features feel instantaneous, as their code is already in the browser’s cache.</p><p><strong>1. </strong><strong>NoPreloading (Default)</strong></p><p>This is the default strategy in Angular and does no preloading at all. Modules are loaded only when the user explicitly navigates to their route.</p><ul><li>Simple explanation: Wait until the user clicks a link before fetching the code for that page.</li><li>Example scenario: A large application with many different sections, like a news website. The homepage loads fast, but clicking on an article page might have a slight delay while that page’s specific bundle is downloaded.</li><li>Implementation: This strategy is used automatically if you don’t specify a preloadingStrategy in your main routing module.</li></ul><pre>// app-routing.module.ts <br>@NgModule({   <br>imports: [RouterModule.forRoot(routes)], // No preloadingStrategy specified   <br>exports: [RouterModule] <br>}) <br>export class AppRoutingModule {}</pre><p><strong>2. </strong><strong>PreloadAllModules</strong></p><p>This strategy preloads every lazy-loaded module in your application after the initial boot up.</p><ul><li>Simple explanation: After the homepage loads, download the code for all other pages in the background while the user is idle.</li><li>Example scenario: A medium-sized application, such as a company’s internal dashboard, where users are likely to visit most of the features throughout their session. It provides a fast initial load while making subsequent navigation feel instant.</li><li>Implementation: Pass PreloadAllModules to the preloadingStrategy property in your root routing module.</li></ul><pre>// app-routing.module.ts <br>import { PreloadAllModules } from &#39;@angular/router&#39;;  <br><br>@NgModule({   <br>imports: [     <br>RouterModule.forRoot(routes, { preloadingStrategy: PreloadAllModules })   <br>],   <br>exports: [RouterModule]<br> }) <br>export class AppRoutingModule {}</pre><p><strong>3. Custom preloading strategy</strong></p><p>You can create a custom preloading strategy by implementing the PreloadingStrategy interface. This allows you to define your own logic for which modules to preload and when.</p><ul><li>Simple explanation: You decide <em>which</em> modules to preload based on custom rules.</li><li>Example scenario: An e-commerce application preloads frequently visited routes like /products but not less common routes such as /admin, optimizing bandwidth.</li><li>Implementation: This involves three steps: adding a flag to your route configuration, creating a service that implements PreloadingStrategy and checks for this flag, and finally, providing this custom service in your root routing module.</li></ul><p>You can create a custom preloading strategy in Angular by implementing the PreloadingStrategy interface. This gives you granular control over which lazy-loaded modules to preload and when, based on your own logic.</p><p>Here is an example of a selective preloading strategy, where a module is preloaded only if a specific preload: true flag is set in its route data.</p><p>1. Create the custom preloading service</p><p>Generate a new service for the custom strategy.</p><pre>ng generate service selective-preloading-strategy</pre><p>Implement the PreloadingStrategy interface in the new service file. The core logic resides in the preload() method, which receives a route object and a load function.</p><ul><li>The route object gives you access to the route&#39;s configuration, including any custom data properties.</li><li>The load() function is the method you call to perform the preloading.</li></ul><p>selective-preloading-strategy.service.ts</p><pre>import { Injectable } from &#39;@angular/core&#39;;<br>import { PreloadingStrategy, Route } from &#39;@angular/router&#39;;<br>import { Observable, of } from &#39;rxjs&#39;;<br>@Injectable({<br>  providedIn: &#39;root&#39;<br>})<br>export class SelectivePreloadingStrategy implements PreloadingStrategy {<br>  preload(route: Route, load: () =&gt; Observable&lt;any&gt;): Observable&lt;any&gt; {<br>    // Check for the &#39;preload: true&#39; flag in the route&#39;s data<br>    if (route.data &amp;&amp; route.data[&#39;preload&#39;]) {<br>      // If the flag is set, call the load function<br>      return load();<br>    }<br>    // Otherwise, skip preloading<br>    return of(null);<br>  }<br>}</pre><p><strong>Configure the routes</strong></p><p>In your main routing file (app-routing.module.ts), import the custom strategy and add a data: { preload: true } property to the routes you want to preload. Configure RouterModule.forRoot to use SelectivePreloadingStrategy.</p><pre>import { RouterModule, Routes } from &#39;@angular/router&#39;;<br>import { SelectivePreloadingStrategy } from &#39;./strategies/selective-preloading.strategy&#39;;<br><br>const routes: Routes = [<br>  {<br>	path: &#39;users&#39;,<br>	loadChildren: () =&gt; import(&#39;./admin/users.module&#39;).then(m =&gt; m.UsersModule),<br>	data: { preload: true }<br>  },<br>  {<br>	path: &#39;profile&#39;,<br>	loadChildren: () =&gt; import(&#39;./settings/profile.module&#39;).then(m =&gt; m.ProfileModule)<br>	// no preload flag here<br>  }<br>];<br><br>@NgModule({<br>  imports: [<br>	RouterModule.forRoot(routes, { preloadingStrategy: SelectivePreloadingStrategy })<br>  ],<br>  exports: [RouterModule],<br>  providers: [SelectivePreloadingStrategy]<br>})<br>export class AppRoutingModule {}</pre><p><strong>Run and observe</strong></p><p>When the application runs, modules with preload: true will be downloaded in the background. Modules without this flag will only download when navigated to. This provides fine-tuned control over preloading, and the same pattern can be extended for more complex strategies.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4f9a783bfe3c" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Understanding Lazy Loading Strategy in Angular]]></title>
            <link>https://medium.com/@raj1996kamal/lazy-loading-strategy-in-angular-4490b4a5d37a?source=rss-accb4f6b70be------2</link>
            <guid isPermaLink="false">https://medium.com/p/4490b4a5d37a</guid>
            <category><![CDATA[web-performance]]></category>
            <category><![CDATA[angular-development]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[lazy-loading]]></category>
            <category><![CDATA[angular]]></category>
            <dc:creator><![CDATA[Rajkamal MM]]></dc:creator>
            <pubDate>Thu, 11 Sep 2025 14:49:24 GMT</pubDate>
            <atom:updated>2025-09-11T15:46:00.845Z</atom:updated>
            <content:encoded><![CDATA[<p>In <a href="https://angular.io/guide/lazy-loading-ngmodules">Angular</a>, lazy loading is a design pattern for loading different parts of your application on-demand. Instead of loading the entire app when it starts (eager loading), it loads only the essential parts. The rest of the application’s features are only loaded when the user actually navigates to them.</p><p>Imagine building a large and complex website, such as an online store.</p><ul><li><strong>Without lazy loading </strong>(eager loading), when a customer lands on the homepage, their browser downloads the code for the homepage, product pages, shopping cart, user account, and admin panel — all at once. This can be a very slow and resource-intensive process.</li><li><strong>With lazy loading</strong>, the customer’s browser downloads only the homepage code first. This makes the website appear and feel faster. The code for the shopping cart is only downloaded when they click the “Add to Cart” button. The admin panel’s code is only downloaded when an administrator logs in and accesses it.</li><li>Example: Setting up a lazy-loaded route</li><li>Here’s how to set up lazy loading for an admin module in an Angular app.</li><li>1. Create a feature module with routing<br>Use the Angular CLI to generate the Admin feature module and its dedicated routing file.</li></ul><pre>ng generate module admin --route admin --module app.module</pre><p>This command automatically updates your main app-routing.module.ts file.</p><p>2. Configure the main routing file (app-routing.module.ts)<br>The loadChildren property tells Angular to load the AdminModule only when the /admin path is visited.</p><p>typescript</p><pre>import { NgModule } from &#39;@angular/core&#39;;<br>import { RouterModule, Routes } from &#39;@angular/router&#39;;</pre><pre>const routes: Routes = [<br>  // <strong>Eagerly loaded route</strong> for the main app<br>  { path: &#39;&#39;, redirectTo: &#39;home&#39;, pathMatch: &#39;full&#39; },<br>  // ... other eagerly loaded routes</pre><pre>  // <strong>Lazy-loaded route</strong> for the admin dashboard<br>  {<br>    path: &#39;admin&#39;,<br>    loadChildren: () =&gt; import(&#39;./admin/admin.module&#39;).then(m =&gt; m.AdminModule)<br>  }<br>];</pre><pre>@NgModule({<br>  imports: [RouterModule.forRoot(routes)],<br>  exports: [RouterModule]<br>})<br>export class AppRoutingModule { }</pre><p>3. Configure the feature module’s routing (admin-routing.module.ts)<br>The admin-routing.module.ts file contains the routes for the components within the Admin module.</p><pre>import { NgModule } from &#39;@angular/core&#39;;<br>import { RouterModule, Routes } from &#39;@angular/router&#39;;<br>import { AdminDashboardComponent } from &#39;./admin-dashboard/admin-dashboard.component&#39;;</pre><pre>const routes: Routes = [<br>  { path: &#39;&#39;, component: AdminDashboardComponent }<br>];</pre><pre>@NgModule({<br>  imports: [RouterModule.forChild(routes)],<br>  exports: [RouterModule]<br>})<br>export class AdminRoutingModule { }<br></pre><p><strong>When to choose each strategy</strong></p><p><strong>Choose eager loading when:</strong></p><ul><li>You are building a small-scale application with a limited number of modules and components.</li><li>Most or all of your application’s features are required immediately upon startup.</li><li>The overall bundle size is small and does not significantly impact the initial load time.</li></ul><p><strong>Choose lazy loading when:</strong></p><ul><li>You are building a large, enterprise-level application with many modules.</li><li>The application contains features that are only used by a small percentage of users, such as an admin dashboard or reporting tools.</li><li>You want to prioritize a fast initial load time and optimal user experience.</li><li>Your application has a complex routing structure that can be easily split into separate feature modules.</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4490b4a5d37a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Understanding Input and Output Decorator in Angular]]></title>
            <link>https://medium.com/@raj1996kamal/understanding-input-and-output-decorator-in-angular-6f5ccd44e1f4?source=rss-accb4f6b70be------2</link>
            <guid isPermaLink="false">https://medium.com/p/6f5ccd44e1f4</guid>
            <category><![CDATA[angular-decorator]]></category>
            <category><![CDATA[angular-development]]></category>
            <category><![CDATA[angular]]></category>
            <category><![CDATA[component-communication]]></category>
            <category><![CDATA[input-and-output]]></category>
            <dc:creator><![CDATA[Rajkamal MM]]></dc:creator>
            <pubDate>Wed, 10 Sep 2025 08:35:16 GMT</pubDate>
            <atom:updated>2025-09-10T08:35:16.409Z</atom:updated>
            <content:encoded><![CDATA[<p>In Angular, <strong>@Input()</strong> and <strong>@Output()</strong> are decorators used to communicate between parent and child components.</p><ul><li><strong>@Input()</strong> allows a parent component to pass data <strong>into</strong> a child component.</li><li><strong>@Output()</strong> allows a child component to send events or data <strong>out</strong> to the parent component.</li></ul><p>This helps components work together in a modular and reusable way.</p><h3>How @Input() works:</h3><p>The child component defines a property decorated with @Input(). The parent binds a value to that property when using the child component’s selector.</p><h3>Example:</h3><p><strong>child.component.ts</strong></p><pre>import { Component, Input } from &#39;@angular/core&#39;;</pre><pre>@Component({<br>  selector: &#39;app-child&#39;,<br>  template: `&lt;p&gt;Message from parent: {{ message }}&lt;/p&gt;`<br>})<br>export class ChildComponent {<br>  @Input() message!: string;  // receive data from parent<br>}</pre><p><strong>parent.component.html</strong></p><pre>&lt;app-child [message]=&quot;&#39;Hello from Parent!&#39;&quot;&gt;&lt;/app-child&gt;</pre><p>Here, the parent sends the string &quot;Hello from Parent!&quot; to the child’s message property.</p><h3>How @Output() works:</h3><p>The child component defines an EventEmitter property decorated with @Output(). When the child wants to notify the parent, it emits an event.</p><h3>Example:</h3><p><strong>child.component.ts</strong></p><pre>import { Component, Output, EventEmitter } from &#39;@angular/core&#39;;</pre><pre>@Component({<br>  selector: &#39;app-child&#39;,<br>  template: `&lt;button (click)=&quot;sendNotification()&quot;&gt;Notify Parent&lt;/button&gt;`<br>})<br>export class ChildComponent {<br>  @Output() notify: EventEmitter&lt;string&gt; = new EventEmitter();</pre><pre>  sendNotification() {<br>    this.notify.emit(&#39;Message from Child!&#39;);<br>  }<br>}</pre><p><strong>parent.component.html</strong></p><pre>&lt;app-child (notify)=&quot;onNotify($event)&quot;&gt;&lt;/app-child&gt;<br>&lt;p&gt;{{ messageFromChild }}&lt;/p&gt;</pre><p><strong>parent.component.ts</strong></p><pre>export class ParentComponent {<br>  messageFromChild: string = &#39;&#39;;</pre><pre>  onNotify(message: string) {<br>    this.messageFromChild = message;<br>  }<br>}</pre><p>In this example:</p><ul><li>The child emits the notify event when the button is clicked.</li><li>The parent listens to (notify) and runs onNotify(), receiving data from the child.</li></ul><h3>Summary</h3><ul><li>@Input() passes data <strong>from parent to child</strong> as a property binding.</li><li>@Output() passes events <strong>from child to parent</strong> as event bindings.</li></ul><p>These two decorators are key to Angular component interaction, making data flow clear and manageable.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6f5ccd44e1f4" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Built-in Pipes in Angular]]></title>
            <link>https://medium.com/@raj1996kamal/built-in-pipes-in-angular-6b3092c357d3?source=rss-accb4f6b70be------2</link>
            <guid isPermaLink="false">https://medium.com/p/6b3092c357d3</guid>
            <category><![CDATA[angular-pipe]]></category>
            <category><![CDATA[angular]]></category>
            <category><![CDATA[built-in-pipe]]></category>
            <dc:creator><![CDATA[Rajkamal MM]]></dc:creator>
            <pubDate>Mon, 25 May 2020 17:33:38 GMT</pubDate>
            <atom:updated>2020-05-25T17:33:38.124Z</atom:updated>
            <content:encoded><![CDATA[<p>In Angular Pipes give you an easy way to transform data directly in your templates. You can create your own custom pipes, and you can also use any of the following ones, which are Built-in and part of the CommonModule.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*44S1RjZ1grNZ5ZT5IYbcxA.png" /></figure><h3>Currency</h3><p>This pipe allows us to format the numbers into different currencies format:</p><pre>{{ Salary | currency:&#39;INR&#39; }}<br>{{ Salary | currency:&#39;EUR&#39;:true }}<br>{{ Salary | currency:&#39;USD&#39;:false:3.2-2 }}</pre><p>There are three possible arguments for this currency pipe they are:</p><ul><li>The first argument is a string with the local currency code.</li><li>The second possible argument is a boolean to show the that will show either the currency symbol, or the currency code. The default is false and shows the currency code.</li><li>The third possible is a string in the format of the decimal pipe to format the number.</li></ul><h3>Date</h3><p>This pipe formats the date values with the specific date format:</p><pre>{{ myDateValue | date:&#39;medium&#39; }}<br>{{ myDateValue | date:&#39;fullDate&#39; }}<br>{{ myDateValue | date:&#39;yy&#39; }}<br>{{ myDateValue | date:&#39;Hm&#39; }}</pre><p>You can use a number of symbols to define a custom format, or you can also use a number of predefined keywords. The available keywords are the following: ‘medium’, ‘short’, ‘fullDate’, ‘longDate’, ‘mediumDate’, ‘shortDate’, ‘mediumTime’ and ‘shortTime’.</p><h3>Json</h3><p>The Json pipe is useful for debugging and displays an object as a JSON string. It uses <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify">JSON.stringify()</a> and <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/parse">JSON.pharse()</a> behind the scenes:</p><pre>{{ JsonObject | json }}</pre><h3>LowerCase &amp; UpperCase</h3><p>These pipes are used to Covert text into either lower case or upper case with the respective pipe:</p><pre>{{ myName | uppercase }}<br>{{ myName | lowercase }}</pre><h3>Decimal</h3><p>The Decimal pipe formats decimal values:</p><pre>{{ someDecimalValue | number:&#39;3.5-4&#39; }}</pre><p>In the above example (‘3.5–4’), 3 is for the minimum number of integer digits, 5 is for the minimum number of fraction digits and 4 is for the maximum number of fraction digits.</p><h3>Percent</h3><p>The Percent pipe transforms a number into it’s percentage value:</p><pre>{{ decimalValue | percent }}<br>{{ decimalValue | percent:&#39;3.2-3&#39; }}</pre><p>The optional argument is a string in the Decimal pipe format.</p><p><a href="https://angular.io/api?type=pipe">There are more built-in pipes available in angular</a> Refer the following URL : <a href="https://angular.io/api?type=pipe">https://angular.io/api?type=pipe</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6b3092c357d3" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[HttpInterceptor in Angular HttpClient]]></title>
            <link>https://medium.com/@raj1996kamal/httpinterceptor-in-angular-httpclient-b9bcedd295ef?source=rss-accb4f6b70be------2</link>
            <guid isPermaLink="false">https://medium.com/p/b9bcedd295ef</guid>
            <category><![CDATA[interceptors]]></category>
            <category><![CDATA[angular-http-interceptor]]></category>
            <category><![CDATA[http-interceptors]]></category>
            <category><![CDATA[http-client]]></category>
            <category><![CDATA[angular-interceptor]]></category>
            <dc:creator><![CDATA[Rajkamal MM]]></dc:creator>
            <pubDate>Sat, 28 Mar 2020 16:47:03 GMT</pubDate>
            <atom:updated>2020-03-28T16:53:04.587Z</atom:updated>
            <content:encoded><![CDATA[<p>Interceptor one of the coolest feature of Angular, Interceptors is a way to communicate with any incoming or outgoing Http requests. They are very similar to the concept of middleware with a framework like Express.</p><p>The Most common use case for Interceptors are:</p><ul><li>Add token for Token-based authentication (or) some custom HTTP header for all outgoing HTTP requests.</li><li>Catch HTTP responses to do some custom formatting (i.e. convert CSV to JSON) before handing the response data to your service/component.</li><li>Validate the Role based access in the application.</li></ul><p>To implement an interceptor, create a class that is injectable and that implements HttpInterceptor.</p><p>You can find all the source code for this project <a href="https://github.com/rajkamal1996/angular-interceptor">here</a>.</p><p><a href="https://stackblitz.com/edit/angular-tnphh2?embed=1&amp;file=src/app/app.module.ts&amp;view=editor">angular-tnphh2 - StackBlitz</a></p><p>The class should define an intercept method to implement HttpInterceptor. The intercept method will have two parameters, req and next which returns an observable of type HttpEvent.</p><ul><li>req is the request object itself and is of type HttpRequest.</li><li>next is the http handler, of type HttpHandler. The handler has a handle method that returns our desired HttpEvent observable.</li></ul><p>Below is a basic interceptor implementation. This interceptor simply uses the RxJS tap operator to log the value of the HttpResponse to the console</p><pre><strong><br>app-interceptor.ts</strong></pre><pre>import { Injectable } from &#39;@angular/core&#39;;</pre><pre>import { HttpInterceptor, HttpHandler, HttpRequest, HttpEvent, HttpResponse }</pre><pre>from &#39;@angular/common/http&#39;;</pre><pre>import { tap } from &#39;rxjs/operators&#39;;</pre><pre>import { Observable } from &#39;rxjs&#39;;</pre><pre>import &#39;rxjs/add/operator/do&#39;;</pre><pre>@Injectable({</pre><pre>providedIn: &#39;root&#39;</pre><pre>})</pre><pre>export class AppInterceptor implements HttpInterceptor {</pre><pre>intercept(</pre><pre>req: HttpRequest&lt;any&gt;,</pre><pre>next: HttpHandler</pre><pre>): Observable&lt;HttpEvent&lt;any&gt;&gt; {</pre><pre>return next.handle(req).pipe(</pre><pre>tap((resp: HttpEvent&lt;any&gt;) =&gt; {</pre><pre>console.log(resp);</pre><pre>if (resp instanceof HttpResponse) {</pre><pre>console.log(&#39;processing response&#39;, resp);</pre><pre>}</pre><pre>})</pre><pre>);</pre><pre>}</pre><pre>}</pre><p>To Use our interceptor in the Angular application provide it in the app module or a feature module using the HTTP_INTERCEPTORS token:</p><pre><strong>app.module.ts</strong><br>import { BrowserModule } from &#39;@angular/platform-browser&#39;;<br>import { NgModule } from &#39;@angular/core&#39;;<br>import { BrowserModule } from &#39;@angular/platform-browser&#39;;<br>import { FormsModule } from &#39;@angular/forms&#39;;<br>import { HttpClientModule, HTTP_INTERCEPTORS } from &#39;@angular/common/http&#39;;</pre><pre>import { AppInterceptor } from &#39;./app-interceptor&#39;;</pre><pre>@NgModule({<br>  declarations: [AppComponent],<br>  imports: [BrowserModule, HttpClientModule],<br>  providers: [<br>    { provide: HTTP_INTERCEPTORS, useClass: AppInterceptor, multi: true }<br>  ],<br>  bootstrap: [AppComponent] H<br>})<br>export class AppModule {}</pre><p>The HTTPResponse of the API call made will the printed in console as given below</p><figure><img alt="Output of Interceptor HTTP Response" src="https://cdn-images-1.medium.com/max/784/1*xnwWj5KjUaCDmV7A3PESgg.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b9bcedd295ef" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>