<?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 Amirsuhail on Medium]]></title>
        <description><![CDATA[Stories by Amirsuhail on Medium]]></description>
        <link>https://medium.com/@asuh1680?source=rss-1d21465b0c52------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*fFdWAsQ0uceJpLnBhm5DZQ.jpeg</url>
            <title>Stories by Amirsuhail on Medium</title>
            <link>https://medium.com/@asuh1680?source=rss-1d21465b0c52------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 05 Dec 2026 22:43:52 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@asuh1680/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[#5th Angular Interview Guide: Core to Advanced Concepts]]></title>
            <link>https://medium.com/@asuh1680/5th-angular-interview-guide-core-to-advanced-concepts-87522341cc17?source=rss-1d21465b0c52------2</link>
            <guid isPermaLink="false">https://medium.com/p/87522341cc17</guid>
            <category><![CDATA[angularconnect]]></category>
            <category><![CDATA[angular-interview]]></category>
            <dc:creator><![CDATA[Amirsuhail]]></dc:creator>
            <pubDate>Wed, 31 Dec 2025 05:53:42 GMT</pubDate>
            <atom:updated>2025-12-31T05:53:42.808Z</atom:updated>
            <content:encoded><![CDATA[<h3>#5 Angular Interview Guide: Core to Advanced Concepts</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*t9SJu4Tzw6dLdGCdQy6NzA.png" /></figure><h3>🔹 Angular Core</h3><h3>Dependency Injection (DI)</h3><p>Dependency Injection in Angular is a design pattern where dependencies (services) are injected into components or other services rather than being created manually. This promotes loose coupling and testability.</p><pre>@Injectable({ providedIn: &#39;root&#39; })<br>export class DataService {<br>  getData() {<br>    return &#39;Hello Angular&#39;;<br>  }<br>}</pre><h3>Singleton Service</h3><p>A singleton service is a service that has only one instance throughout the application lifecycle. When provided in root, Angular ensures a single instance is shared.</p><h3>providedIn: &#39;root&#39; vs providedIn: &#39;any&#39;</h3><ul><li><strong>root</strong>: Service is a singleton across the entire app.</li><li><strong>any</strong>: A new instance is created in each lazy-loaded module.</li><li><strong>Module Providers</strong>: If a service is provided in a specific module, its scope is limited to that module.</li></ul><h3>Modules in Angular</h3><p>Modules group related components, directives, pipes, and services.</p><ul><li>If a service is provided in a module, it is scoped to that module.</li><li>It won’t affect global variables unless explicitly shared.</li></ul><h3>Service Provided in Root</h3><p>When provided in root:</p><ul><li>Angular registers the service in the root injector.</li><li>Internally, Angular maintains a single instance.</li><li>Other ways: providers array in @NgModule or @Component.</li></ul><h3>🔹 Components &amp; Templates</h3><h3>Template Reference Variable</h3><p>A variable declared in a template using # to reference DOM elements or Angular components.</p><pre>&lt;input #myInput type=&quot;text&quot;&gt;<br>&lt;button (click)=&quot;log(myInput.value)&quot;&gt;Log&lt;/button&gt;</pre><h3>@ViewChild vs @ViewChildren</h3><ul><li><strong>@ViewChild</strong>: Gets a single child element/component.</li><li><strong>@ViewChildren</strong>: Gets a QueryList of multiple child elements/components.</li></ul><pre>@ViewChild(&#39;myInput&#39;) inputRef!: ElementRef;<br>@ViewChildren(&#39;items&#39;) items!: QueryList&lt;ElementRef&gt;;</pre><h3>ng-content &amp; ng-template</h3><ul><li><strong>ng-content</strong>: Enables content projection (parent injects HTML into child).</li><li><strong>ng-template</strong>: Defines a template that can be rendered conditionally.</li></ul><pre>&lt;!-- Child Component --&gt;<br>&lt;div&gt;<br>  &lt;ng-content&gt;&lt;/ng-content&gt;<br>&lt;/div&gt;</pre><pre>&lt;!-- Parent Component --&gt;<br>&lt;child&gt;<br>  &lt;button&gt;Click Me&lt;/button&gt;<br>&lt;/child&gt;</pre><p>Internally, Angular uses the Shadow DOM concept to project parent content into child slots.</p><h3>🔹 Forms</h3><h3>ControlValueAccessor</h3><p>It’s an interface that allows custom form controls to integrate with Angular forms.</p><pre>export class CustomInputComponent implements ControlValueAccessor {<br>  writeValue(value: any): void { /* update UI */ }<br>  registerOnChange(fn: any): void { /* save callback */ }<br>  registerOnTouched(fn: any): void { /* save callback */ }<br>}</pre><p>We use it when building reusable custom form components.</p><h3>🔹 Directives</h3><h3>Types of Directives</h3><ul><li><strong>Component Directives</strong>: With templates.</li><li><strong>Structural Directives</strong>: Change DOM structure (*ngIf, *ngFor).</li><li><strong>Attribute Directives</strong>: Change appearance/behavior.</li></ul><h3>Custom Directive Example</h3><pre>@Directive({ selector: &#39;[appColor]&#39; })<br>export class ColorDirective {<br>  @Input(&#39;appColor&#39;) color!: string;</pre><pre>  constructor(private el: ElementRef) {}</pre><pre>  ngOnInit() {<br>    this.el.nativeElement.style.color = this.color;<br>  }<br>}</pre><h3>@HostListener</h3><p>Used to listen to host element events.</p><pre>@HostListener(&#39;mouseenter&#39;) onMouseEnter() {<br>  this.el.nativeElement.style.backgroundColor = &#39;yellow&#39;;<br>}</pre><h3>@HostBinding</h3><p>Binds a property of the host element.</p><pre>@HostBinding(&#39;style.color&#39;) textColor = &#39;blue&#39;;</pre><h3>🔹 Pipes</h3><h3>Custom Pipe Example</h3><pre>@Pipe({ name: &#39;phoneFormat&#39; })<br>export class PhoneFormatPipe implements PipeTransform {<br>  transform(value: string): string {<br>    return value.replace(/(\d{4})(\d{3})(\d{3})/, &#39;$1-$2-$3&#39;);<br>  }<br>}</pre><p>Usage:</p><pre>{{ &#39;9999222222&#39; | phoneFormat }} &lt;!-- Output: 9999-222-222 --&gt;</pre><h3>🔹 RxJS</h3><h3>Promise vs Observable</h3><ul><li><strong>Promise</strong>: Handles a single value asynchronously.</li><li><strong>Observable</strong>: Streams multiple values over time.</li></ul><h3>Observable vs Subject</h3><ul><li><strong>Observable</strong>: Unicast, each subscriber gets its own execution.</li><li><strong>Subject</strong>: Multicast, all subscribers share the same execution.</li></ul><h3>takeUntil Operator</h3><p>Unsubscribes from an observable when another observable emits.</p><pre>this.data$.pipe(takeUntil(this.destroy$)).subscribe();</pre><h3>switchMap vs exhaustMap</h3><ul><li><strong>switchMap</strong>: Cancels previous observable when a new one starts.</li><li><strong>exhaustMap</strong>: Ignores new observables until the current one completes.</li></ul><h3>🔹 JavaScript Concepts</h3><h3>Event Loop</h3><p>The event loop manages execution of synchronous and asynchronous tasks.</p><ul><li><strong>Microtasks</strong>: Promises, MutationObserver.</li><li><strong>Macrotasks</strong>: setTimeout, setInterval.</li></ul><h3>Closure</h3><p>A closure is a function that remembers variables from its lexical scope even when executed outside.</p><pre>function outer() {<br>  let count = 0;<br>  return function inner() {<br>    count++;<br>    return count;<br>  };<br>}<br>const fn = outer();<br>console.log(fn()); // 1<br>console.log(fn()); // 2</pre><h3>Predict Output</h3><pre>let x = 1;<br>setTimeout(() =&gt; console.log(x), 0);<br>x++;<br>console.log(x);</pre><p>Output:</p><pre>2<br>2</pre><p>Explanation: <a href="https://console.log/">console.log</a>(x) runs synchronously (prints 2). Then setTimeout runs later, also printing 2.</p><p>✅ This guide covers Angular core, components, forms, directives, pipes, RxJS, and JavaScript concepts with examples and snippets — perfect for interview prep or a Medium post.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=87522341cc17" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Step-by-Step Guide: Upgrading Angular 12 to Angular 19]]></title>
            <link>https://medium.com/@asuh1680/step-by-step-guide-upgrading-angular-12-to-angular-19-c839a661d92d?source=rss-1d21465b0c52------2</link>
            <guid isPermaLink="false">https://medium.com/p/c839a661d92d</guid>
            <category><![CDATA[angular-19]]></category>
            <category><![CDATA[angular12]]></category>
            <category><![CDATA[angular]]></category>
            <category><![CDATA[angular-migration]]></category>
            <dc:creator><![CDATA[Amirsuhail]]></dc:creator>
            <pubDate>Wed, 31 Dec 2025 05:41:28 GMT</pubDate>
            <atom:updated>2025-12-31T05:41:28.904Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_v7B5onuEV_Subr28yVNfA.png" /></figure><p>Upgrading Angular projects across multiple major versions can feel daunting, but with a structured approach, you can move safely from Angular 12 all the way to Angular 19. This guide walks you through each phase, ensuring your environment is set up correctly and your project remains stable at every step.</p><h3>PHASE 0 — Environment Setup (Mandatory)</h3><h3>0.1 Install Node Version Manager (Windows)</h3><p>Use <a href="https://github.com/coreybutler/nvm-windows">nvm-windows</a> to manage Node versions easily.</p><p>Open <strong>Command Prompt</strong> as Administrator.</p><h3>0.2 Install &amp; Use Node 16</h3><pre>nvm install 16<br>nvm use 16<br>node -v</pre><p>✔ Must show v16.x.x</p><h3>0.3 Clean Project &amp; Verify Angular 12 Works</h3><pre>cd angular-12-crud-master\angular-12-crud-master<br>rd /s /q node_modules<br>del package-lock.json<br>npm cache clean --force</pre><pre>npm install<br>npx ng serve</pre><p>✔ App must run before upgrading.</p><h3>PHASE 1 — Angular Upgrades (One Version at a Time)</h3><p>Upgrade step by step, committing after each successful run.</p><h3>Angular 12 → 13</h3><pre>npx ng update @angular/core@13 @angular/cli@13<br>npm install<br>npx ng serve<br>git add .<br>git commit -m &quot;Upgrade Angular 12 to 13&quot;</pre><h3>Angular 13 → 14</h3><pre>npx ng update @angular/core@14 @angular/cli@14<br>npm install<br>npx ng serve<br>git add .<br>git commit -m &quot;Upgrade Angular 13 to 14&quot;</pre><h3>Angular 14 → 15</h3><pre>npx ng update @angular/core@15 @angular/cli@15<br>npm install<br>npx ng serve<br>git add .<br>git commit -m &quot;Upgrade Angular 14 to 15&quot;</pre><h3>PHASE 2 — Switch Node Version (Important)</h3><p>Angular 16+ requires Node 18.</p><h3>Switch to Node 18</h3><pre>nvm install 18<br>nvm use 18<br>node -v</pre><p>✔ Must show v18.x.x</p><h3>Angular 15 → 16</h3><pre>npx ng update @angular/core@16 @angular/cli@16<br>npm install<br>npx ng serve<br>git add .<br>git commit -m &quot;Upgrade Angular 15 to 16&quot;</pre><h3>Angular 16 → 17</h3><pre>npx ng update @angular/core@17 @angular/cli@17<br>npm install<br>npx ng serve<br>git add .<br>git commit -m &quot;Upgrade Angular 16 to 17&quot;</pre><h3>Angular 17 → 18</h3><pre>npx ng update @angular/core@18 @angular/cli@18<br>npm install<br>npx ng serve<br>git add .<br>git commit -m &quot;Upgrade Angular 17 to 18&quot;</pre><h3>Angular 18 → 19</h3><pre>npx ng update @angular/core@19 @angular/cli@19<br>npm install<br>npx ng serve<br>git add .<br>git commit -m &quot;Upgrade Angular 18 to 19&quot;</pre><h3>PHASE 3 — Final Cleanup (Optional but Recommended)</h3><p>Remove old Angular CLI global versions:</p><pre>npm uninstall -g @angular/cli<br>npm install -g @angular/cli@19</pre><h3>Verify Final State</h3><p>Run:</p><pre>ng version</pre><p>✅ Expected Final State:</p><pre>Item           Value<br><br>Angular        19.x<br><br>Node           18.x<br><br>RxJS           7.x<br><br>TypeScript     5.x<br><br>zone.js        0.14+<br><br>Build tool     ESBuild/Vite</pre><h3>Troubleshooting</h3><p>If something fails:</p><pre>rm -rf node_modules<br>del package-lock.json<br>npm install<br>npx ng serve</pre><h3>🎯 Next Steps</h3><p>Once you’re safely on Angular 19, you can:</p><ul><li>Modernize to <strong>standalone APIs</strong></li><li>Add <strong>signals</strong></li><li>Replace *ngIf with @if</li><li>Optimize builds with <strong>ESBuild/Vite</strong></li></ul><p>By following this phased approach, you ensure smooth upgrades without breaking your project. Never jump ahead — stability at each step is key!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c839a661d92d" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[ Building a Med‑Bucket RX App with Angular + NgRx (Step by Step)]]></title>
            <link>https://medium.com/@asuh1680/building-a-med-bucket-rx-app-with-angular-ngrx-step-by-step-1a9f982e7fe3?source=rss-1d21465b0c52------2</link>
            <guid isPermaLink="false">https://medium.com/p/1a9f982e7fe3</guid>
            <category><![CDATA[angular]]></category>
            <category><![CDATA[ngrx]]></category>
            <category><![CDATA[ngrx-store]]></category>
            <category><![CDATA[rxjs-operators]]></category>
            <dc:creator><![CDATA[Amirsuhail]]></dc:creator>
            <pubDate>Sat, 27 Dec 2025 18:05:13 GMT</pubDate>
            <atom:updated>2025-12-27T18:05:13.480Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*TNYX6lPrVcCfrlf-yjLjwg.png" /></figure><p>In this tutorial, we will walk through creating a medicine management system using Angular and NgRx. The goal is to manage medicine storage, allow users to select different types of medicines, add and remove them from a shopping bucket, and handle the state effectively using NgRx.</p><h3>Step 1: Define Actions</h3><p>Actions are the starting point in NgRx. They describe what can happen in our app.</p><pre><br>export const addToMedBucket = createAction(<br>  &#39;[MedBucket] MedAdd&#39;,<br>  props&lt;{ payload: MedBucket }&gt;()<br>);<br><br>export const removeToMedBucket = createAction(<br>  &#39;[MedBucket] MedRemove&#39;,<br>  props&lt;{ payload: Partial&lt;MedBucket&gt; }&gt;()<br>);</pre><p>Grouped actions for groceries:</p><pre>export const medGroceryAction = createActionGroup({<br>  source: &#39;Med Grocery API&#39;,<br>  events: {<br>    &#39;Load medGroceris&#39;: emptyProps(),<br>    &#39;Load medGroceries Success&#39;: props&lt;{ payload: MedGrocery[] }&gt;(),<br>    &#39;Load medGroceries Failure&#39;: emptyProps()<br>  }<br>});</pre><h3>Step 2: Create Reducers</h3><p>Reducers handle state changes based on actions.</p><p><strong>MedBucket Reducer:</strong></p><pre>export const medBuckerReducer = createReducer(<br>  initialMedBucket,<br>  on(addToMedBucket, (state, action) =&gt; {<br>    const existItem = state.find(item =&gt; item.id === action.payload.id);<br>    if (existItem) {<br>      return state.map(item =&gt;<br>        item.id === action.payload.id<br>          ? { ...item, quantity: item.quantity + action.payload.quantity }<br>          : item<br>      );<br>    } else return [...state, action.payload];<br>  }),<br>  on(removeToMedBucket, (state, action) =&gt; {<br>    const existItem = state.find(item =&gt; item.id === action.payload.id);<br>    if (existItem &amp;&amp; existItem.quantity &gt; 1) {<br>      return state.map(item =&gt;<br>        item.id === action.payload.id<br>          ? { ...item, quantity: item.quantity - 1 }<br>          : item<br>      );<br>    } else {<br>      return state.filter(item =&gt; item.id !== action.payload.id);<br>    }<br>  })<br>);</pre><p>MedGroceries Reducer:</p><pre>export const medgrosReducer = createReducer(<br>  initialMedStorage,<br>  on(medGroceryAction.loadMedGroceriesSuccess, (state, action) =&gt; action.payload),<br>  on(medGroceryAction.loadMedGroceriesFailure, () =&gt; [])<br>);</pre><h3>Step 3: Create Effects</h3><p>Effects handle side‑effects like API calls.</p><pre>@Injectable() export class MoviesEffects2 {<br> private actions$ = inject(Actions); <br>private moviesService = inject(Medicinservice); <br>loadMovies$ = createEffect(() =&gt; { return this.actions$.<br>pipe( ofType(medGroceryAction.loadMedGroceris), <br>exhaustMap(() =&gt; this.moviesService.<br>fetchAllMedGroceries().pipe(<br> map((medgroceries: any) =&gt;<br> medGroceryAction.loadMedGroceriesSuccess({ payload: medgroceries }) ),<br> catchError(() =&gt; of(medGroceryAction.loadMedGroceriesFailure())) <br>) <br>)<br> );<br> });<br> }</pre><p></p><h3>Step 4: Create Selectors</h3><p>Selectors help us query the store state.</p><pre>export const selectMedGroceris = (state: { medGrocery: MedGrocery[] }) =&gt;<br> state.medGrocery;<br> export const selectGroceryByType = (type: string) =&gt; <br>createSelector(selectMedGroceris, (state) =&gt;<br> { return state.filter(item =&gt; item.category === type); });</pre><p></p><h3>Step 5: Build the Component</h3><p>Finally, we connect everything inside our Angular component.</p><pre>@Component({ selector: &#39;app-medicine-storage&#39;, <br>imports: [CommonModule],<br> templateUrl: &#39;./medicine-storage.html&#39;, <br>styleUrl: &#39;./medicine-storage.scss&#39;, }) <br>export class MedicineStorage { <br>medGroceries$?: Observable; <br>filteredMedGoceries$?: Observable;<br> constructor(private store: Store)<br> { <br>this.medGroceries$ = store.select(selectMedGroceris); <br>} <br>onTypeChange(event: Event) { <br>const value = (event.target as HTMLSelectElement).value;<br> if (value) this.filteredMedGoceries$ = this.store.select(selectGroceryByType(value)); <br>else this.filteredMedGoceries$ = undefined; } <br>increment(data: MedGrocery) { <br>const payload = { …data, quantity: 1 }; <br>this.store.dispatch(addToMedBucket({ payload }));<br> } <br>decrement(item: MedGrocery) <br>{ <br>const payload = { id: item.id }; <br>this.store.dispatch(removeToMedBucket({ payload })); <br>} <br>}</pre><p></p><h3>Step 6: Template</h3><p>Here’s the template that ties UI with store actions:</p><pre>&lt;div class=&quot;container&quot;&gt;<br>  &lt;h1&gt;Groceries&lt;/h1&gt;<br>  &lt;select (change)=&quot;onTypeChange($event)&quot; class=&quot;type-select&quot;&gt;<br>    &lt;option value=&quot;&quot;&gt;Select type&lt;/option&gt;<br>    &lt;option value=&quot;Pain Relief&quot;&gt;Fruit&lt;/option&gt;<br>    &lt;option value=&quot;Antibiotic&quot;&gt;Snacks&lt;/option&gt;<br>    &lt;option value=&quot;Allergy&quot;&gt;Snacks&lt;/option&gt;<br>    &lt;option value=&quot;Gastric&quot;&gt;Snacks&lt;/option&gt;<br>  &lt;/select&gt;<br><br>  &lt;ul class=&quot;grocery-list&quot;&gt;<br>    @for(groc of (filteredMedGoceries$ | async) ?? (medGroceries$ | async); track groc.id) {<br>      &lt;li class=&quot;grocery-item&quot;&gt;<br>        &lt;span class=&quot;increment-button&quot; (click)=&quot;increment(groc)&quot;&gt;+&lt;/span&gt;<br>        {{ groc.brandName }}<br>        &lt;span class=&quot;decrement-button&quot; (click)=&quot;decrement(groc)&quot;&gt;-&lt;/span&gt;<br>      &lt;/li&gt;<br>    } @empty {<br>      &lt;li&gt;loading..&lt;/li&gt;<br>    }<br>  &lt;/ul&gt;<br>&lt;/div&gt;</pre><h3>Step 7: Add the Service to Fetch Data</h3><p>To make the application dynamic, you’ll need to connect to a backend service to fetch the list of medicines. In this step, we’ll create a service to interact with an API that provides data about different medicines.</p><p>Create a medicinservice.ts file in the src/app folder:</p><pre>import { Injectable } from &#39;@angular/core&#39;;<br>import { HttpClient } from &#39;@angular/common/http&#39;;<br>import { Observable } from &#39;rxjs&#39;;<br>import { MedGrocery } from &#39;./model/medgrocery.model&#39;;</pre><pre>@Injectable({<br>  providedIn: &#39;root&#39;<br>})<br>export class Medicinservice {</pre><pre>  private apiUrl = &#39;https://api.example.com/medicines&#39;; // Replace with the actual API endpoint</pre><pre>  constructor(private http: HttpClient) {}</pre><pre>  fetchAllMedGroceries(): Observable&lt;MedGrocery[]&gt; {<br>    return this.http.get&lt;MedGrocery[]&gt;(this.apiUrl);<br>  }<br>}</pre><ul><li>This service fetches data from the backend using <strong>HttpClient</strong>.</li><li>Make sure to replace the apiUrl with the correct endpoint from which you are fetching medicine data.</li></ul><p>Next, register the service in your Angular module by adding it to the providers array if it’s not already injected using providedIn: &#39;root&#39;.</p><h3>Step 8: Set Up Store for Medicine List</h3><p>You need to register the reducers in your <strong>StoreModule</strong> to ensure that the state management works correctly.</p><p>Edit the app.module.ts to include the NgRx store and reducers:</p><pre>import { NgModule } from &#39;@angular/core&#39;;<br>import { BrowserModule } from &#39;@angular/platform-browser&#39;;<br>import { StoreModule } from &#39;@ngrx/store&#39;;<br>import { EffectsModule } from &#39;@ngrx/effects&#39;;<br>import { HttpClientModule } from &#39;@angular/common/http&#39;;<br>import { AppComponent } from &#39;./app.component&#39;;<br>import { medBucketReducer } from &#39;./store/reducers/medbucket.reducer&#39;;<br>import { medgrosReducer } from &#39;./store/reducers/medgros.reducer&#39;;<br>import { MedGroceryEffects } from &#39;./store/effects/medgrocery.effects&#39;;</pre><pre>@NgModule({<br>  declarations: [AppComponent, MedicineStorageComponent, MedicinBucketComponent],<br>  imports: [<br>    BrowserModule,<br>    StoreModule.forRoot({<br>      medBucket: medBucketReducer,<br>      medGrocery: medgrosReducer<br>    }),<br>    EffectsModule.forRoot([MedGroceryEffects]),<br>    HttpClientModule<br>  ],<br>  providers: [],<br>  bootstrap: [AppComponent]<br>})<br>export class AppModule {}</pre><p>This registers the <strong>medBucketReducer</strong> and <strong>medgrosReducer</strong> to manage the state of your shopping bucket and medicine list, and integrates the <strong>MedGroceryEffects</strong> for handling async actions (such as fetching medicine data).</p><h3>Step 9: Set Up Selectors for State Access</h3><p>Selectors help you access specific pieces of state in a Redux-style store. You can create selectors to filter and select different types of medicines (like Pain Relief, Antibiotics, etc.).</p><p>Create a medgros.selector.ts file to define your selectors:</p><pre>import { createSelector } from &#39;@ngrx/store&#39;;<br>import { MedGrocery } from &#39;../../model/medgrocery.model&#39;;</pre><pre>export const selectMedGroceris = (state: { medGrocery: MedGrocery[] }) =&gt; state.medGrocery;</pre><pre>export const selectGroceryByType = (type: string) =&gt;<br>  createSelector(selectMedGroceris, (state) =&gt; {<br>    return state.filter(item =&gt; item.category === type);<br>  });</pre><ul><li>selectMedGroceris: This selector fetches all medicines from the state.</li><li>selectGroceryByType: This selector filters the medicines based on the category (e.g., &quot;Pain Relief&quot; or &quot;Antibiotics&quot;).</li></ul><h3>Step 10: Setup and Testing</h3><p>Now that the basic app structure is set up, let’s ensure everything is working. Here’s how you can test and verify:</p><ol><li><strong>Run the App</strong>: Start the Angular development server by running:</li></ol><ul><li>ng serve</li></ul><ol><li><strong>Test the Filtering</strong>: In your application, select different categories (like Pain Relief, Antibiotic) and verify if the medicine list updates accordingly.</li><li><strong>Test Adding/Removing Items from Bucket</strong>: Click on the “+” and “-” buttons next to each medicine to add/remove them from your shopping bucket. Ensure that the quantities in the bucket update correctly.</li></ol><p></p><p>🎯 Final Thoughts</p><p>By following these steps sequentially:</p><ol><li>Define <strong>Actions</strong></li><li>Create <strong>Reducers</strong></li><li>Add <strong>Effects</strong></li><li>Write <strong>Selectors</strong></li><li>Build the <strong>Component</strong></li><li>Connect with <strong>Template</strong></li></ol><p>You now have a fully working Angular + NgRx medicine bucket app. This pattern is reusable for any inventory or shopping cart system.</p><p>👉 On Medium, this layout will render cleanly: headings, numbered steps, and fenced code blocks with syntax highlighting instead of black background blocks.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1a9f982e7fe3" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Pagination Component in Angular Using Signals and RxJS]]></title>
            <link>https://medium.com/@asuh1680/pagination-component-in-angular-using-signals-and-rxjs-9dd05f31d2f4?source=rss-1d21465b0c52------2</link>
            <guid isPermaLink="false">https://medium.com/p/9dd05f31d2f4</guid>
            <category><![CDATA[angular]]></category>
            <dc:creator><![CDATA[Amirsuhail]]></dc:creator>
            <pubDate>Fri, 26 Dec 2025 05:52:21 GMT</pubDate>
            <atom:updated>2025-12-26T05:52:21.076Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*25IttOnFyedQZjURwXSs6g.png" /></figure><p>Pagination is a must-have feature when dealing with large datasets. Instead of rendering everything at once, pagination improves <strong>performance</strong>, <strong>readability</strong>, and <strong>user experience</strong>.</p><p>In this post, I’ll walk through how I built a <strong>pagination component from scratch in Angular</strong>, using:</p><ul><li>✅ Angular <strong>Signals</strong></li><li>✅ RxJS operators</li><li>✅ Manual page calculation</li><li>✅ Clean UI navigation (Next, Previous, Page Numbers)</li></ul><h3>What We’re Building</h3><p>We’ll create a pagination system that:</p><ul><li>Fetches all products from an API</li><li>Displays a fixed number of items per page</li><li>Allows navigation using:</li><li>⬅️ Previous button</li><li>➡️ Next button</li><li>🔢 Page numbers</li><li>Efficiently updates UI using <strong>Signals</strong></li></ul><h3>1. Component State &amp; Setup</h3><p>Let’s start with the core state required for pagination.</p><pre>import { Component, signal } from &#39;@angular/core&#39;;<br>import { Paginationservice } from &#39;../paginationservice&#39;;<br>import { map, tap } from &#39;rxjs&#39;;<br>import { Product } from &#39;../interface/pagination.interface&#39;;<br>import { CommonModule } from &#39;@angular/common&#39;;</pre><pre>@Component({<br>  selector: &#39;app-try-paginationbyself&#39;,<br>  imports: [CommonModule],<br>  templateUrl: &#39;./try-paginationbyself.html&#39;,<br>  styleUrl: &#39;./try-paginationbyself.scss&#39;,<br>})<br>export class TryPaginationbyself {<br>  productsData = signal&lt;Product[]&gt;([]);</pre><pre>  PAGE_SIZE = 10;<br>  startIndex = 0;<br>  endIndex = 0;</pre><pre>  totalproduct = 0;<br>  noOfPages = 0;<br>  currentPage = 0;</pre><pre>  numbers: number[] = [];<br>  productsWitPagination: Product[] = [];</pre><pre>  constructor(private paginationService: Paginationservice) {}<br>}</pre><h3>Why Signals?</h3><p>Signals make state updates simple and efficient. When productsData changes, Angular updates the UI automatically—no manual change detection needed.</p><h3>2. Fetching Data &amp; Initial Pagination</h3><p>On initialization:</p><ul><li>We fetch all products</li><li>Calculate total pages</li><li>Slice data for the first page</li></ul><pre>ngOnInit() {<br>  this.paginationService<br>    .getProducts()<br>    .pipe(<br>      tap(originalProduct =&gt; {<br>        this.noOfPages = Math.ceil(<br>          originalProduct.products.length / this.PAGE_SIZE<br>        );<br>        this.productsWitPagination = originalProduct.products;<br>        this.numbers = [...Array(this.noOfPages).keys()];<br>      }),<br>      map(product =&gt;<br>        product.products.slice(this.startIndex, this.PAGE_SIZE)<br>      )<br>    )<br>    .subscribe(res =&gt; {<br>      this.productsData.set(res);<br>    });<br>}</pre><h3>What’s happening here?</h3><ul><li>tap() → used for side effects (calculating pages)</li><li>map() → slices data for the current page</li><li>signal.set() → updates the UI</li></ul><h3>3. Page Navigation Logic</h3><h3>Go to a Specific Page</h3><pre>gotoNextPage(page: number) {<br>  if (page &gt;= this.noOfPages || page &lt; 0) return;</pre><pre>  this.currentPage = page;<br>  this.startIndex = page * this.PAGE_SIZE;<br>  this.endIndex = this.startIndex + this.PAGE_SIZE;</pre><pre>  const products = this.productsWitPagination.slice(<br>    this.startIndex,<br>    this.endIndex<br>  );</pre><pre>  this.productsData.set(products);<br>}</pre><p>✔ Prevents invalid page access<br> ✔ Dynamically slices product data</p><h3>Next Page</h3><pre>nextPage() {<br>  this.gotoNextPage(this.currentPage + 1);<br>}</pre><h3>Previous Page</h3><pre>prevPage() {<br>  this.gotoNextPage(this.currentPage - 1);<br>}</pre><h3>4. Pagination Template (HTML)</h3><h3>Product Listing</h3><pre>&lt;div class=&quot;container&quot;&gt;<br>  @for (product of productsData(); track product.id) {<br>    &lt;div class=&quot;product-card&quot;&gt;<br>      &lt;img<br>        class=&quot;imageCls&quot;<br>        [src]=&quot;product.images&quot;<br>        [alt]=&quot;product.title&quot;<br>      /&gt;<br>      &lt;span&gt;{{ product.title }}&lt;/span&gt;<br>    &lt;/div&gt;<br>  }<br>&lt;/div&gt;</pre><p>✔ Uses @for for better performance<br> ✔ track product.id avoids unnecessary re-renders</p><h3>Pagination Controls</h3><pre>&lt;div class=&quot;pagination-container&quot;&gt;<br>  &lt;button<br>    [disabled]=&quot;currentPage == 0&quot;<br>    (click)=&quot;prevPage()&quot;<br>  &gt;<br>    ⬅️<br>  &lt;/button&gt;</pre><pre>  &lt;ng-container *ngFor=&quot;let page of numbers&quot;&gt;<br>    &lt;span<br>      [class]=&quot;&#39;pagination-buttons &#39; + (page == currentPage ? &#39;active&#39; : &#39;&#39;)&quot;<br>      (click)=&quot;gotoNextPage(page)&quot;<br>    &gt;<br>      {{ page }}<br>    &lt;/span&gt;<br>  &lt;/ng-container&gt;</pre><pre>  &lt;button<br>    [disabled]=&quot;currentPage == numbers.length - 1&quot;<br>    (click)=&quot;nextPage()&quot;<br>  &gt;<br>    ➡️<br>  &lt;/button&gt;<br>&lt;/div&gt;</pre><h3>UX Enhancements</h3><ul><li>Disabled buttons at boundaries</li><li>Active page highlighting</li><li>Clickable page numbers</li></ul><h3>5. Key Takeaways</h3><p>📌 Pagination is easy when data slicing is handled correctly</p><p>⚡ Angular <strong>Signals</strong> simplify state updates</p><p>🔄 RxJS tap + map cleanly separate logic</p><p>🎯 Manual pagination gives full control over UI and behavior</p><p>🚀 This approach works great for medium-sized datasets</p><h3>Possible Enhancements</h3><ul><li>Add server-side pagination</li><li>Add page size selector</li><li>Add lazy loading</li><li>Animate page transitions</li></ul><h3>Final Thoughts</h3><p>Building pagination manually helps you understand:</p><ul><li>Data slicing</li><li>State management</li><li>UI navigation logic</li></ul><p>Once you grasp this, integrating libraries or server-side pagination becomes much easier.</p><p>If you found this useful, feel free to clap 👏 and share your thoughts.<br> Happy coding! 🚀</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9dd05f31d2f4" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Autocomplete Using Template Forms and Reactive Forms in Angular]]></title>
            <link>https://medium.com/@asuh1680/autocomplete-using-template-forms-and-reactive-forms-in-angular-3b7cdee3e56d?source=rss-1d21465b0c52------2</link>
            <guid isPermaLink="false">https://medium.com/p/3b7cdee3e56d</guid>
            <category><![CDATA[angular]]></category>
            <dc:creator><![CDATA[Amirsuhail]]></dc:creator>
            <pubDate>Fri, 26 Dec 2025 05:41:41 GMT</pubDate>
            <atom:updated>2025-12-26T05:41:41.324Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*d0CcUolZD-jEjHOktGIw1w.png" /></figure><p>Autocomplete is one of those UI features that significantly improves user experience. Whether it’s searching recipes, users, or products, providing instant suggestions makes an app feel faster and smarter.</p><p>In this post, I’ll walk you through how I enhanced an <strong>autocomplete feature in Angular</strong> using <strong>both Template-driven Forms and Reactive Forms</strong>, while also applying <strong>RxJS best practices</strong> like debouncing, filtering, and switching streams.</p><h3>What We’re Building</h3><p>We’ll implement:</p><ul><li>Autocomplete using <strong>Template-driven Forms</strong></li><li>Autocomplete using <strong>Reactive Forms</strong></li><li>Debounced API calls</li><li>Focus/blur handling for showing results</li><li>Efficient rendering using trackBy</li><li>Angular <strong>Signals</strong> for state management</li></ul><h3>1. UI Template (HTML)</h3><p>We’ll have <strong>two search inputs</strong>:</p><ol><li>One using ngModel (template-driven)</li><li>One using FormControl (reactive)</li></ol><h3>Template-driven Form Autocomplete</h3><pre>&lt;div class=&quot;app&quot;&gt;<br>  &lt;h2&gt;Autocomplete search&lt;/h2&gt;  &lt;div class=&quot;search-box&quot;&gt;<br>    &lt;input<br>      type=&quot;text&quot;<br>      [(ngModel)]=&quot;searchText&quot;<br>      (ngModelChange)=&quot;onChangeInput($event)&quot;<br>      placeholder=&quot;Search recipes...&quot;<br>      (blur)=&quot;onBlur(&#39;template&#39;)&quot;<br>      (focus)=&quot;onFocus(&#39;template&#39;)&quot;<br>    /&gt;<br>  &lt;/div&gt;</pre><pre>  @if (isFocus) {<br>    &lt;div class=&quot;result-container&quot;&gt;<br>      @for (receipe of resultsOfrecipes(); track trackByFn(receipe)) {<br>        &lt;p class=&quot;results&quot;&gt;{{ receipe.name }}&lt;/p&gt;<br>      }<br>    &lt;/div&gt;<br>  }<br>}</pre><h3>Reactive Form Autocomplete</h3><pre>&lt;div class=&quot;app&quot;&gt;<br>  &lt;div class=&quot;search-box&quot;&gt;<br>    &lt;input<br>      type=&quot;text&quot;<br>      [formControl]=&quot;searchTextReactive&quot;<br>      (blur)=&quot;onBlur(&#39;reactive&#39;)&quot;<br>      (focus)=&quot;onFocus(&#39;reactive&#39;)&quot;<br>    /&gt;<br>  &lt;/div&gt;</pre><pre>  @if (isReactiveFocus) {<br>    &lt;div class=&quot;result-container&quot;&gt;<br>      @for (receipe of resultsOfrecipesreactive(); track receipe.id) {<br>        &lt;p class=&quot;results&quot;&gt;{{ receipe.name }}&lt;/p&gt;<br>      }<br>    &lt;/div&gt;<br>  }<br>}</pre><h3>2. Component Setup</h3><p>We use:</p><ul><li>signal() for reactive state</li><li>Subject for template-driven search</li><li>FormControl for reactive search</li></ul><pre>@Component({<br>  selector: &#39;app-autocomplete&#39;,<br>  imports: [CommonModule, FormsModule, ReactiveFormsModule],<br>  templateUrl: &#39;./autocomplete.html&#39;,<br>  styleUrl: &#39;./autocomplete.scss&#39;,<br>  changeDetection: ChangeDetectionStrategy.OnPush,<br>})<br>export class Autocomplete {<br>  searchText = &#39;&#39;;<br>  searchTextReactive = new FormControl(&#39;&#39;);</pre><pre>  resultsOfrecipes = signal&lt;any[]&gt;([]);<br>  resultsOfrecipesreactive = signal&lt;any[]&gt;([]);</pre><pre>  isFocus = false;<br>  isReactiveFocus = false;</pre><pre>  searchSubject = new Subject&lt;string&gt;();</pre><pre>  constructor(private service: AutocompleteService) {}<br>}</pre><h3>3. Template-driven Form Logic (RxJS Subject)</h3><p>Here, we manually push values into a Subject and control the stream.</p><pre>ngOnInit() {<br>  this.searchSubject<br>    .pipe(<br>      debounceTime(500),<br>      distinctUntilChanged(),<br>      filter(text =&gt; text.trim().length &gt; 0),<br>      switchMap(text =&gt; this.service.searchRecipe(text))<br>    )<br>    .subscribe((res: any) =&gt; {<br>      this.resultsOfrecipes.set(res.recipes);<br>    });<br>}</pre><h3>Triggering the Search</h3><pre>onChangeInput(value: string) {<br>  this.searchSubject.next(value);<br>}</pre><p>✅ <strong>Why this works well</strong></p><ul><li>debounceTime avoids spamming the API</li><li>distinctUntilChanged prevents duplicate calls</li><li>switchMap cancels previous requests</li></ul><h3>4. Reactive Form Logic</h3><p>Reactive forms make this even cleaner because valueChanges is already an observable.</p><pre>constructor(private service: AutocompleteService) {<br>  this.searchTextReactive.valueChanges<br>    .pipe(<br>      debounceTime(500),<br>      switchMap(value =&gt; {<br>        const text = value?.trim();</pre><pre>        if (!text) {<br>          return this.service.searchRecipe(text);<br>        }</pre><pre>        if (text.length &lt;= 3) {<br>          return EMPTY;<br>        }</pre><pre>        return this.service.searchRecipe(text);<br>      })<br>    )<br>    .subscribe((res: any) =&gt; {<br>      this.resultsOfrecipesreactive.set(res.recipes);<br>    });<br>}</pre><p>✅ <strong>Enhancements</strong></p><ul><li>Avoids calls for very short input</li><li>Automatically reacts to value changes</li><li>Cleaner and more scalable</li></ul><h3>5. Focus &amp; Blur Handling</h3><p>To control when results appear:</p><pre>onFocus(type: string) {<br>  type === &#39;reactive&#39;<br>    ? (this.isReactiveFocus = true)<br>    : (this.isFocus = true);<br>}</pre><pre>onBlur(type: string) {<br>  type === &#39;reactive&#39;<br>    ? (this.isReactiveFocus = false)<br>    : (this.isFocus = false);<br>}</pre><h3>6. Performance Optimization with trackBy</h3><pre>trackByFn(item: any): number {<br>  return item.id;<br>}</pre><p>This prevents Angular from re-rendering unchanged list items.</p><h3>Key Takeaways</h3><ul><li>🧩 <strong>Template-driven forms</strong> offer flexibility but need manual stream control</li><li>⚡ <strong>Reactive forms</strong> integrate naturally with RxJS</li><li>🛑 debounceTime + switchMap is the golden combo for autocomplete</li><li>🚀 Angular <strong>Signals</strong> simplify state updates</li><li>🎯 Focus-based rendering improves UX</li></ul><h3>Final Thoughts</h3><p>Both approaches work well, but for <strong>scalable and complex applications</strong>, <strong>Reactive Forms</strong> are usually the better choice. That said, understanding both gives you flexibility as an Angular developer.</p><p>If you found this helpful, feel free to clap 👏 or share your own autocomplete enhancements!</p><p>Happy coding! 🚀</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3b7cdee3e56d" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Mastering Asynchronous Programming in Angular: Promises, Observables, and Async/Await]]></title>
            <link>https://medium.com/@asuh1680/mastering-asynchronous-programming-in-angular-promises-observables-and-async-await-b8a90b931ccd?source=rss-1d21465b0c52------2</link>
            <guid isPermaLink="false">https://medium.com/p/b8a90b931ccd</guid>
            <category><![CDATA[promises]]></category>
            <category><![CDATA[asyncawait]]></category>
            <category><![CDATA[observables]]></category>
            <category><![CDATA[angular]]></category>
            <dc:creator><![CDATA[Amirsuhail]]></dc:creator>
            <pubDate>Tue, 23 Dec 2025 05:43:21 GMT</pubDate>
            <atom:updated>2025-12-23T05:43:21.587Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-miNos1WMgglSE9lHQ-Fng.png" /></figure><p>Asynchronous programming is one of the most important skills for modern developers. Angular apps heavily rely on asynchronous operations, from fetching data via HTTP to responding to user interactions in real time.</p><p>Angular provides several ways to handle asynchronous operations: <strong>Promises</strong>, <strong>async/await</strong>, and <strong>Observables</strong>. While they all deal with async tasks, they do so differently. Understanding their differences, strengths, and limitations is key to building clean, scalable Angular applications.</p><p>This article dives into each of these approaches, including practical use cases, conversions, and best practices.</p><h3>1. Promises in Angular</h3><p>A <strong>Promise</strong> represents the eventual result of an asynchronous operation. It can be in one of three states:</p><ul><li><strong>Pending</strong> — the initial state</li><li><strong>Fulfilled (Resolved)</strong> — operation completed successfully</li><li><strong>Rejected</strong> — operation failed</li></ul><pre>        Pending<br>        /     \<br>  Fulfilled     Rejected<br>   (resolve)    (reject)</pre><p>Once a Promise is resolved or rejected, its value is immutable.</p><h3>Example: Using Promises in Angular Service</h3><pre>@Injectable({ providedIn: &#39;root&#39; })<br>export class AuthService {<br>  fetchUser(): Promise&lt;User&gt; {<br>    return fetch(&#39;https://jsonplaceholder.typicode.com/users&#39;)<br>      .then(result =&gt; result.json());<br>  }<br>}</pre><h3>Using Async/Await with Promises</h3><pre>async getUser() {<br>  try {<br>    const user = await this.authService.fetchUser();<br>    console.log(user.name);<br>  } catch (error) {<br>    console.error(&#39;Failed to load user:&#39;, error);<br>  }<br>}</pre><p><strong>Key Points</strong>:</p><ul><li>Promises are <strong>eager</strong> — they start immediately when created.</li><li>They emit <strong>single values</strong> only.</li><li>They <strong>cannot be canceled</strong> once started.</li></ul><h3>2. Observables in Angular</h3><p>An <strong>Observable</strong> is a more powerful way to handle asynchronous operations. Unlike Promises, Observables:</p><ul><li>Can emit <strong>multiple values over time</strong></li><li>Can be <strong>canceled</strong> using unsubscribe</li><li>Are <strong>lazy</strong> — they only execute when subscribed</li></ul><h3>Example: HTTP Request with Observables</h3><pre>@Injectable({ providedIn: &#39;root&#39; })<br>export class AuthService {<br>  constructor(private http: HttpClient) {}</pre><pre>  fetchUsers(): Observable&lt;User[]&gt; {<br>    return this.http.get&lt;User[]&gt;(&#39;https://jsonplaceholder.typicode.com/users&#39;);<br>  }<br>}</pre><h3>Subscribing to an Observable</h3><pre>this.authService.fetchUsers().subscribe({<br>  next: users =&gt; console.log(users),<br>  error: err =&gt; console.error(&#39;Error loading users:&#39;, err)<br>});</pre><p><strong>Key Points</strong>:</p><ul><li>Observables are <strong>cold</strong> by default — they won’t start until subscribed.</li><li>They support <strong>cancellation</strong> via unsubscribe.</li><li>Can be combined, mapped, or transformed using <strong>RxJS operators</strong>.</li></ul><h3>3. Promises vs Observables</h3><p>FeaturePromiseObservableLazy vs EagerEagerLazyMultiple valuesNoYesCancelableNoYesOperatorsLimitedRxJS provides rich operatorsUsageSimple async tasksStreams, events, complex async flows</p><h3>4. Async/Await in Angular</h3><p>async/await is syntactic sugar for Promises. It allows writing asynchronous code as if it were synchronous.</p><pre>async loadUsers() {<br>  try {<br>    const users = await this.authService.fetchUser();<br>    console.log(users);<br>  } catch (err) {<br>    console.error(&#39;Error:&#39;, err);<br>  }<br>}</pre><p><strong>Key Points</strong>:</p><ul><li>Only works with <strong>Promises</strong>.</li><li>Makes async code <strong>more readable</strong>.</li><li>Doesn’t work directly with Observables (needs conversion).</li></ul><h3>5. Converting Between Promises and Observables</h3><p>Sometimes you may need to convert between the two:</p><h3>Observable → Promise</h3><pre>const users$ = this.authService.fetchUsers();<br>const users = await users$.toPromise();<br>console.log(users);</pre><h3>Promise → Observable</h3><pre>const userPromise = this.authService.fetchUser();<br>const user$ = from(userPromise);<br>user$.subscribe(user =&gt; console.log(user));</pre><h3>6. Using the Async Pipe in Angular Templates</h3><p>Angular provides the <strong>async pipe</strong> to handle Observables and Promises in templates without manually subscribing:</p><pre>&lt;div *ngIf=&quot;users$ | async as users&quot;&gt;<br>  &lt;ul&gt;<br>    &lt;li *ngFor=&quot;let user of users&quot;&gt;{{ user.name }}&lt;/li&gt;<br>  &lt;/ul&gt;<br>&lt;/div&gt;</pre><p><strong>Benefits</strong>:</p><ul><li>Automatic subscription and unsubscription</li><li>Cleaner templates</li><li>Works for both <strong>Promises</strong> and <strong>Observables</strong></li></ul><h3>7. Combining Async/Await and Observables</h3><p>Sometimes you want the power of Observables but prefer async/await syntax:</p><pre>async loadFirstUser() {<br>  const users = await this.authService.fetchUsers().pipe(first()).toPromise();<br>  console.log(users[0]);<br>}</pre><p>Here we use RxJS operators like first() to control the Observable before converting it to a Promise.</p><h3>8. Advanced RxJS vs Async/Await</h3><ul><li><strong>RxJS</strong>: Best for <strong>streams of data</strong>, complex transformations, and event handling.</li><li><strong>Async/Await</strong>: Best for <strong>single asynchronous values</strong>, sequential logic, or when simplicity is preferred.</li></ul><p><strong>Tip:</strong> Don’t overcomplicate. Use Observables for multiple values/events and async/await for single-value async calls.</p><h3>9. Best Practices</h3><ol><li>Prefer <strong>Observables</strong> for HTTP calls in Angular because Angular’s HttpClient returns Observables.</li><li>Use <strong>async pipe</strong> instead of manual subscription whenever possible.</li><li>Use <strong>Promises + async/await</strong> for simple sequential async operations.</li><li>Cancel subscriptions in components using takeUntil or unsubscribe to prevent memory leaks.</li><li>Leverage <strong>RxJS operators</strong> to handle retries, transformations, and error handling elegantly.</li></ol><p>Angular gives you multiple ways to handle asynchronous code. By understanding <strong>Promises, async/await, and Observables</strong>, and knowing when to use each, you can build robust, efficient, and maintainable applications.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b8a90b931ccd" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Interview Preperation #11]]></title>
            <link>https://medium.com/@asuh1680/interview-preperation-11-911521d47e5f?source=rss-1d21465b0c52------2</link>
            <guid isPermaLink="false">https://medium.com/p/911521d47e5f</guid>
            <category><![CDATA[interview]]></category>
            <category><![CDATA[angular-interview]]></category>
            <dc:creator><![CDATA[Amirsuhail]]></dc:creator>
            <pubDate>Mon, 22 Dec 2025 07:28:29 GMT</pubDate>
            <atom:updated>2025-12-22T07:30:43.507Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9TH0dDmZH2XiIiOl7e8sXg.png" /></figure><h4>What an Angular Interview at middel-scale company’s interview Taught Me</h4><p>Recently, I had the opportunity to interview with middel-scale company, and the experience turned out to be a great reminder of how important strong fundamentals are — especially in <strong>Angular, RxJS, and JavaScript</strong>.</p><p>In this article, I’m sharing the key topics that came up during the interview, with the hope that it helps others preparing for Angular-based roles.</p><h3>Angular Concepts Discussed</h3><h3>Standalone Components</h3><p>One of the main discussion points was Angular’s move toward <strong>standalone components</strong>. These were introduced to address the complexity of the traditional NgModule-based architecture. Standalone components reduce boilerplate, improve tree-shaking, and make components easier to reuse and lazy-load.</p><h3>Change Detection and OnPush Strategy</h3><p>We discussed Angular’s change detection mechanism and how it propagates changes through the component tree. The OnPush strategy was highlighted as a performance optimization technique that limits checks to input changes, events, or observable emissions. While powerful, it requires careful handling of immutability and state updates.</p><h3>Observables vs Promises</h3><p>Another core topic was the difference between <strong>Observables</strong> and <strong>Promises</strong>. Promises resolve a single value and cannot be canceled, whereas Observables support multiple emissions, cancellation, and rich composition through operators — making them ideal for asynchronous data streams.</p><h3>RxJS Mapping Operators</h3><p>A clear understanding of RxJS operators was expected:</p><ul><li>switchMap cancels previous subscriptions when a new one starts</li><li>mergeMap allows parallel execution</li><li>concatMap processes streams sequentially</li><li>exhaustMap ignores new emissions until the current one completes</li></ul><p>Each operator serves a specific use case, and choosing the wrong one can lead to bugs or performance issues.</p><h3>RxJS Schedulers</h3><p>Schedulers were discussed as a way to control <strong>when</strong> and <strong>how</strong> observables execute. They play an important role in managing concurrency, timing, and performance in reactive applications.</p><h3>Angular Signals</h3><p>Angular Signals came up as a newer reactive primitive designed for fine-grained reactivity. Signals integrate closely with Angular’s change detection and help reduce unnecessary re-renders, offering a more predictable and performant approach to state updates.</p><h3>NgRx State Management</h3><p>The interview also covered <strong>NgRx</strong> and its role in managing application state. We discussed how <strong>actions</strong> represent events, while <strong>reducers</strong> handle immutable state transitions — providing a predictable and scalable state management pattern for large applications.</p><h3>Dynamic Routing</h3><p>Dynamic routing was another important topic, especially in enterprise applications. This involves building routes based on API responses, user roles, or permissions, often combined with route guards and resolvers.</p><h3>JavaScript Problems</h3><p>Two JavaScript exercises were part of the discussion:</p><ul><li>Splitting an array into chunks of a fixed size</li><li>Converting repeated values in an array to 1 while preserving the last element</li></ul><p>These problems emphasized logical thinking and familiarity with array manipulation rather than complex algorithms.</p><h3>Final Thoughts</h3><p>This interview experience reinforced a key lesson: <strong>deep understanding of core concepts matters more than surface-level knowledge of tools</strong>. Angular fundamentals, RxJS behavior, and JavaScript problem-solving remain critical skills for frontend engineers.</p><p>Sharing this experience in case it helps others preparing for Angular interviews or revisiting their fundamentals.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=911521d47e5f" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>