<?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 Abdelrhman Abdelatif on Medium]]></title>
        <description><![CDATA[Stories by Abdelrhman Abdelatif on Medium]]></description>
        <link>https://medium.com/@AbdelrahmanAbdelatif?source=rss-bfa31e9959bf------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*zU1wZVd3KVchu9jLle_yrQ.jpeg</url>
            <title>Stories by Abdelrhman Abdelatif on Medium</title>
            <link>https://medium.com/@AbdelrahmanAbdelatif?source=rss-bfa31e9959bf------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 17 Nov 2026 02:52:10 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@AbdelrahmanAbdelatif/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[Why Your Code Doesn’t Run in Order A Deep Dive into the JavaScript Event Loop]]></title>
            <link>https://medium.com/@AbdelrahmanAbdelatif/why-your-code-doesnt-run-in-order-a-deep-dive-into-the-javascript-event-loop-97fe1183966b?source=rss-bfa31e9959bf------2</link>
            <guid isPermaLink="false">https://medium.com/p/97fe1183966b</guid>
            <category><![CDATA[macrotask]]></category>
            <category><![CDATA[micro-tasks]]></category>
            <category><![CDATA[javascript-event-loop]]></category>
            <dc:creator><![CDATA[Abdelrhman Abdelatif]]></dc:creator>
            <pubDate>Wed, 22 Oct 2025 18:54:40 GMT</pubDate>
            <atom:updated>2025-10-22T19:05:34.612Z</atom:updated>
            <content:encoded><![CDATA[<p>Have you ever written seemingly simple JavaScript code, only for the output to defy your expectations? Let’s analyze a short code snippet and uncover why its messages don’t appear in sequence, and how the <strong>Event Loop</strong> keeps JavaScript running smoothly.</p><pre>console.log(&quot;Hello&quot;);<br><br>setTimeout(() =&gt; {<br>  console.log(&quot;setTimeout Zero Delay&quot;);<br>}, 0);<br><br>Promise.resolve().then(() =&gt; {<br>  console.log(&quot;Promise Resolved&quot;);<br>});<br><br>setTimeout(() =&gt; {<br>  console.log(&quot;setTimeout Long Delay&quot;);<br>}, 1000);<br><br>console.log(&quot;Goodbye&quot;);</pre><h3>The Conceptual Explanation: The Event Loop</h3><p>To understand this ordering, we must realize that JavaScript isn’t a single continuous block of execution. It’s a system composed of three main parts:</p><h3>1. The Call Stack</h3><p>This is where all <strong>Synchronous</strong> code is executed line by line. Code in the Call Stack has <strong>absolute priority</strong>.</p><h3>2. The Task Queues</h3><p>When the JavaScript engine encounters <strong>Asynchronous</strong> code, it doesn’t execute it immediately.</p><h3>3. The Event Loop</h3><p>The Event Loop is the mechanism that constantly monitors the Call Stack and the queues. Its fundamental job is to:</p><blockquote><strong><em>If the Call Stack is empty, move tasks from the queues into the Call Stack for execution.</em></strong></blockquote><h3>Step-by-Step Execution Analysis</h3><p>Let’s trace the code execution through the Event Loop cycle:</p><h3>Phase 1: Synchronous Code (Maximum Priority)</h3><ul><li>console.log(&quot;Hello&quot;); ➡️ <strong>Executed immediately.</strong></li><li>setTimeout(() =&gt; { ... }, 0); ➡️ Not synchronous. Callback is scheduled and moved to the <strong>Macrotask Queue</strong>.</li><li>Promise.resolve().then(() =&gt; { ... }); ➡️ Not synchronous. Callback is resolved immediately and moved to the <strong>Microtask Queue</strong>.</li><li>setTimeout(() =&gt; { ... }, 1000); ➡️ Not synchronous. Callback is scheduled and moved to the <strong>Macrotask Queue</strong>.</li><li>console.log(&quot;Goodbye&quot;); ➡️ <strong>Executed immediately.</strong></li></ul><h3>Phase 2: Event Loop Kicks In (The Priority Shift)</h3><p>The <strong>Call Stack is now empty</strong>, so the Event Loop starts working. The golden rule here is:</p><blockquote><strong><em>The Microtask Queue must be completely emptied before the Event Loop checks the Macrotask Queue.</em></strong></blockquote><p><strong>Microtask Queue (High Priority):</strong></p><ul><li>The Promise.resolve().then() callback is pulled into the Call Stack and executed.</li><li>console.log(&quot;Promise: Resolved&quot;); ➡️ <strong>Executed.</strong></li></ul><p><strong>Macrotask Queue (Low Priority):</strong></p><ul><li>After the Microtask Queue is cleared, the setTimeout with the (0) delay is pulled in.</li><li>console.log(&quot;setTimeout Zero Delay&quot;); ➡️ <strong>Executed.</strong></li></ul><p><strong>Macrotask Queue (Longer Delay):</strong></p><ul><li>After the 1000ms delay has elapsed, the final setTimeout is pulled in.</li><li>console.log(&quot;setTimeout Long Delay&quot;); ➡️ <strong>Executed.</strong></li></ul><p><strong><em>The Actual Output</em></strong></p><pre>Hello<br>Goodbye<br>Promise: Resolved<br>setTimeout Zero Delay<br>setTimeout Long Delay</pre><p>Conclusion ::</p><ol><li><strong>Synchronous code runs first, always.</strong></li><li>Once the Call Stack is clear, the Event Loop takes over.</li><li><strong>Promises (Microtasks) take priority over Timers (Macrotasks).</strong> This is why the promise resolved immediately, even beating the “zero delay” timer.</li></ol><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=97fe1183966b" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Stop Using px for Everything: An Accessibility and Responsive Design Guide for CSS Units]]></title>
            <link>https://medium.com/@AbdelrahmanAbdelatif/stop-using-px-for-everything-an-accessibility-and-responsive-design-guide-for-css-units-d896570bd4b1?source=rss-bfa31e9959bf------2</link>
            <guid isPermaLink="false">https://medium.com/p/d896570bd4b1</guid>
            <dc:creator><![CDATA[Abdelrhman Abdelatif]]></dc:creator>
            <pubDate>Sat, 23 Aug 2025 06:35:34 GMT</pubDate>
            <atom:updated>2025-08-23T06:35:34.656Z</atom:updated>
            <content:encoded><![CDATA[<p>How many times have you meticulously built a layout, only to see it break when a user zooms in or changes their font settings? The culprit is often lurking in your CSS: the overuse of px units.</p><p>This guide will explain the crucial difference between absolute and relative CSS units and why making the switch will dramatically improve your websites for every user.</p><p><strong>Understanding the Basics: Absolute vs. Relative</strong></p><p>Think of CSS units like two different types of rulers.</p><ul><li><strong>Absolute Units (The Fixed Ruler):</strong> An absolute unit, like px, is a fixed measurement. A 16px font will always be 16px on the screen, no matter what. It&#39;s a precise tool for a predictable world, but the web is anything but predictable. Absolute units don&#39;t adapt to user settings or device characteristics.</li><li><strong>Relative Units (The Proportional Ruler):</strong> A relative unit, like rem or em, changes its size based on another value. This makes your designs fluid and adaptable. They scale up or down to create a better experience for users on different devices and with different needs.</li></ul><h3>The Real Problem with px: It Breaks Accessibility</h3><p>The biggest issue with px isn&#39;t just responsiveness-it&#39;s accessibility.</p><p>Many users, especially those with visual impairments, increase their browser’s default font size to make text readable. When you hard-code everything in px, you ignore this setting. The result?</p><ul><li>🧩 <strong>Broken Layouts</strong>: Your meticulously crafted spacing collapses as larger text overlaps or spills out of containers.</li><li>😠 <strong>Frustrated Users:</strong> They are forced to manually zoom, often causing awkward horizontal scrolling and a terrible experience.</li></ul><p>By using px for everything, you are actively locking out a segment of your audience. Relative units are the key to fixing this.</p><h3>The Solution: Embrace rem and em</h3><p>So, what should you use instead? Meet your new best friends: rem and em. While both are relative, they reference different things.</p><h3>rem (Root Em)</h3><p>The rem unit is relative to the font size of the root (&lt;html&gt;) element. By default, this is 16px in most browsers, so 1rem = 16px.</p><p>The Magic: If a user changes their default font size to 20px, the root size changes. Instantly, <em>every</em> measurement on your site defined in rem scales proportionally. Your layout, spacing, and typography all adapt seamlessly. It&#39;s the single most powerful change you can make for accessibility.</p><p>✅ Best Use Cases for rem:</p><ul><li>Font sizes (headings, body text)</li><li>Margin and padding (ensures spacing scales with text)</li><li>Widths and heights (for overall layout consistency)</li></ul><h3>em</h3><p>The em unit is relative to the font size of its direct parent element. This makes it powerful but potentially tricky due to compounding.</p><pre>.button {<br>  font-size: 1rem; /* 16px */<br>  padding: 0.75em; /* Padding is 0.75 * 16px = 12px */<br>}<br><br>.button .icon {<br>  height: 1em; /* Icon height is 1 * 16px = 16px */<br>  width: 1em;<br>}</pre><p><strong><em>Example</em></strong><em>: Using </em><em>em for padding and icon sizing that should scale with a button&#39;s specific text size.</em></p><p>✅ Best Use Cases for em:</p><ul><li>Styling elements that should scale with their parent’s font size (e.g., padding inside a button).</li><li>Creating scalable components where internal proportions must be maintained.</li></ul><h3>How to Start Using rem Today (Without the Math)</h3><p>You’re convinced, but recalculating px to rem sounds tedious. Don&#39;t worry, you don&#39;t have to do the math!</p><ol><li>Set a Base Font Size: In your CSS, set the html selector to a percentage that makes the default 1rem equal to 10px for easier calculations.</li></ol><pre>html {<br>  font-size: 62.5%; /* This makes 1rem = 10px (based on 16px default) */<br>}</pre><ul><li>Why 62.5%? Because 10px / 16px = 0.625.*</li></ul><p>Use rem Liberally: Now, you can think in px but write in rem.</p><ul><li>Need 24px? Use 2.4rem.</li><li>Need 16px? Use 1.6rem.</li><li>Need 8px? Use 0.8rem.</li></ul><p>This simple setup preserves user accessibility settings while making your developer life much easier.</p><h3>Conclusion</h3><p>Adopting rem and em isn&#39;t just a technical best practice; it&#39;s a commitment to building a more inclusive and resilient web. Your designs will gracefully adapt to any screen, any zoom level, and any user need.</p><p>It’s a small change in your code that makes a massive difference in someone’s experience.</p><h4><strong><em>I hope you found this guide helpful. I’m already working on the next one, so stay tuned”</em></strong></h4><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d896570bd4b1" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[No AppModule? No Problem — Dependency Injection in Standalone Angular V14+]]></title>
            <link>https://medium.com/@AbdelrahmanAbdelatif/no-appmodule-no-problem-dependency-injection-in-standalone-angular-v14-4c5bb47428da?source=rss-bfa31e9959bf------2</link>
            <guid isPermaLink="false">https://medium.com/p/4c5bb47428da</guid>
            <dc:creator><![CDATA[Abdelrhman Abdelatif]]></dc:creator>
            <pubDate>Sat, 09 Aug 2025 13:27:07 GMT</pubDate>
            <atom:updated>2025-08-11T18:27:05.111Z</atom:updated>
            <content:encoded><![CDATA[<h3>No AppModule? No Problem -Dependency Injection in Standalone Angular V14+</h3><p>With Angular 14+, we gained <strong>Standalone Components</strong>, which let us build Angular applications <strong>without AppModule</strong></p><p>In this article (third in the DI series), we’ll see <strong>how DI works without a module</strong>, explore <strong>different provider levels</strong>, and understand the <strong>benefits</strong> of this approach.</p><p>With Angular 14+, we got <strong>Standalone Components-</strong>meaning you can build an Angular app without<strong> AppModule</strong><br> But that raises a big question:</p><blockquote><em>Without </em><strong><em>AppModule</em></strong><em>, where do we register our services for Dependency Injection?</em></blockquote><p>The answer: <strong>DI still works exactly the same at the core</strong>, but the <strong>places where you register providers change</strong>.</p><p>This article explains <strong>all provider registration options</strong> in standalone Angular and when to use each one.</p><p>How We Did It Before (with Modules)</p><p>In traditional Angular apps, services were usually registered in:</p><p>1- @NgModule.providers</p><pre>@NgModule({<br>  providers: [LoggerService]<br>})<br>export class AppModule {}</pre><p>2- provideIn in the service itself</p><pre>@Injectable({ providedIn: &#39;root&#39; })<br>export class LoggerService { ... }</pre><h3>How It Works Now (Standalone Mode)</h3><p>In <strong>standalone</strong> apps, there’s no AppModule-but Angular lets you register providers in <strong>four main places</strong>:</p><p>1- <strong><em>providedIn</em></strong> in the<strong> service</strong> (Global) Exactly like before.</p><pre>@Injectable({ providedIn: &#39;root&#39; })<br>export class LoggerService {<br>  log(msg: string) {<br>    console.log(`[LOG] ${msg}`);<br>  }<br>}</pre><p>Best for <strong>global services</strong> used across the whole app.<br> Tree-shakable.</p><p>2- In<strong> <em>bootstrapApplication()</em></strong> (Global) Pass providers during the app bootstrap.</p><pre>bootstrapApplication(AppComponent, {<br>  providers: [LoggerService]<br>});</pre><p>Good when you want <strong>app-wide scope</strong> but <strong>don’t want providedIn hardcoded</strong>.<br> Useful for <strong>library services</strong> or <strong>overrides</strong>.</p><p>3-<strong>In a standalone component</strong> (Component scope) Add providers in the component’s providers array.</p><pre>@Component({<br>  selector: &#39;app-user&#39;,<br>  standalone: true,<br>  template: `&lt;button (click)=&quot;sayHi()&quot;&gt;Hi&lt;/button&gt;`,<br>  providers: [LoggerService]<br>})<br>export class UserComponent {<br>  constructor(private logger: LoggerService) {}<br>  sayHi() {<br>    this.logger.log(&#39;Hello from UserComponent&#39;);<br>  }<br>}</pre><p>Each <strong>component instance</strong> gets its <strong>own service instance</strong>.<br> Great for <strong>isolated state</strong> per widget/tab.</p><p>4- <strong>In route configuration</strong> (Route scope) Register providers directly in a route definition.</p><pre>export const routes: Routes = [<br>  {<br>    path: &#39;admin&#39;,<br>    loadComponent: () =&gt; import(&#39;./admin.component&#39;)<br>      .then(m =&gt; m.AdminComponent),<br>    providers: [AdminService]<br>  }<br>];</pre><p>Service exists <strong>only when the route is active</strong>.<br> Reduces memory usage.</p><p><strong><em>Fully Example</em></strong></p><pre>@Injectable({ providedIn: &#39;root&#39; })<br>export class CounterService {<br>  private count = 0;<br>  increment() { this.count++; }<br>  getCount() { return this.count; }<br>}<br><br>@Injectable()<br>export class LoggerService {<br>  log(msg: string) { console.log(`[LOG]: ${msg}`); }<br>}<br><br>@Component({<br>  selector: &#39;app-feature&#39;,<br>  standalone: true,<br>  template: `<br>    &lt;button (click)=&quot;add()&quot;&gt;Add&lt;/button&gt;<br>    Count: {{ count }}<br>  `,<br>  providers: [LoggerService] // Component-level<br>})<br>export class FeatureComponent {<br>  count = 0;<br>  constructor(<br>    private counter: CounterService,<br>    private logger: LoggerService<br>  ) {}<br>  add() {<br>    this.counter.increment();<br>    this.count = this.counter.getCount();<br>    this.logger.log(&#39;Button clicked&#39;);<br>  }<br>}<br><br>bootstrapApplication(FeatureComponent, {<br>  providers: [LoggerService] // Bootstrap-level<br>});</pre><h4>Benefits of <strong>Standalone DI</strong></h4><ul><li><strong>No AppModule : </strong>simpler app setup.</li><li><strong>Clear service scopes</strong> : global, per-route, or per-component.</li><li><strong>Tree-shaking : </strong>unused services removed from the bundle.</li><li><strong>Better memory usage</strong> : route-scoped services destroyed when not needed.</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4c5bb47428da" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Understanding Dependency Injection Scopes in Angular(providedIn: 'root') VS Component-Level…]]></title>
            <link>https://medium.com/@AbdelrahmanAbdelatif/understanding-dependency-injection-scopes-in-angular-providedin-root-vs-component-level-39f293e51385?source=rss-bfa31e9959bf------2</link>
            <guid isPermaLink="false">https://medium.com/p/39f293e51385</guid>
            <dc:creator><![CDATA[Abdelrhman Abdelatif]]></dc:creator>
            <pubDate>Wed, 06 Aug 2025 21:33:20 GMT</pubDate>
            <atom:updated>2025-08-09T06:33:47.282Z</atom:updated>
            <content:encoded><![CDATA[<h3>Understanding Dependency Injection Scopes in Angular(providedIn: &#39;root&#39;) VS Component-Level Providers</h3><p>In the previous article ( <a href="https://medium.com/@Body44444444444/understanding-dependency-injection-the-what-why-and-how-with-angular-examples-2d1cb6101f86"><strong><em>understanding-dependency-injection-the-what-why-and-how-with-angular-example</em></strong></a>), we explored what <strong>Dependency Injection (DI)</strong> is and how Angular leverages it to manage services efficiently and testably.</p><p>In this post, we’ll dive deeper into how Angular controls <strong>the lifetime and scope</strong> of injected services — particularly</p><p>In Angular, where you provide a service determines its scope and lifecycle. Let’s dive into the differences between root-level and component-level providers and how they impact your application.</p><blockquote><em>What’s the difference between </em><em>providedIn: &#39;root&#39; and providing a service at the component level?</em></blockquote><ol><li>Service Provided in the root Injector</li></ol><p>When you declare a service like this</p><pre>@Injectable ( {<br> providedIn: &#39;root&#39;,<br>})<br>export class LoggerService {<br> log(message: string) {<br> console.log(&#39;LOGINNG::&#39;, message);<br> }<br>}</pre><p>Here You’re telling Angular</p><p>Create a <strong>singleton instance</strong> of this service, available <strong>application-wide</strong>.</p><h4>Why use providedIn: &#39;root&#39;?</h4><ul><li>It’s the <strong><em>default</em></strong> and most efficient way to <strong><em>share a service globally</em></strong>.</li><li>Ensures a <strong>single shared instance</strong> throughout the app.</li><li>Ideal for stateless or shared logic like API services, logging, or caching.</li></ul><p>2. Service Provided in the providers array of a Component</p><pre>@Component({<br>  selector: &#39;app-user&#39;,<br>  templateUrl: &#39;./user.component.html&#39;,<br>  providers: [LoggerService]<br>})<br>export class UserComponent {<br>  constructor(private logger: LoggerService) {<br>    this.logger.log(&#39;UserComponent created&#39;);<br>  }<br>}</pre><p>Here This means</p><blockquote>Angular creates a <strong>new instance</strong> of LoggerService <strong>each time</strong> this component is created.</blockquote><blockquote>Once the component is destroyed, the service instance is also destroyed.</blockquote><h4>Why use component-level providers?</h4><ul><li>You want <strong>isolated service instances</strong> per component.</li><li>Useful for component-specific state or logic (like local counters or internal configs).</li><li>Supports encapsulation and makes component state independent.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vLQo5d5D-7K0uHXuVnXFLA.png" /></figure><p><strong>Simple Example</strong> : Counter Service</p><p>Service Definition</p><pre>export class CounterService {<br>  private count = 0;<br><br>  increment() {<br>    this.count++;<br>  }<br><br>  getCount() {<br>    return this.count;<br>  }<br>}</pre><p>Global Singleton Usage</p><pre>@Injectable({ providedIn: &#39;root&#39; })<br>export class CounterService { ... }</pre><pre>@Component({<br>  selector: &#39;app-global-counter&#39;,<br>  template: `&lt;button (click)=&quot;add()&quot;&gt;Click&lt;/button&gt; Count: {{ count }}`<br>})<br>export class GlobalCounterComponent {<br>  count = 0;<br><br>  constructor(private counter: CounterService) {}<br><br>  add() {<br>    this.counter.increment();<br>    this.count = this.counter.getCount();<br>  }<br>}</pre><p>Local Instance Usage</p><pre>@Component({<br>  selector: &#39;app-local-counter&#39;,<br>  template: `&lt;button (click)=&quot;add()&quot;&gt;Click&lt;/button&gt; Count: {{ count }}`,<br>  providers: [CounterService]<br>})<br>export class LocalCounterComponent {<br>  count = 0;<br><br>  constructor(private counter: CounterService) {}<br><br>  add() {<br>    this.counter.increment();<br>    this.count = this.counter.getCount();<br>  }<br>}</pre><p>If you use two instances of app-local-counter, each one tracks its own clicks.<br> But app-global-counter shares the same counter between all its usages.</p><p>When to use</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*pwopwHuXg5FwiihFaeIZcw.png" /></figure><ul><li>Angular allows you to control how services are shared and reused.</li><li>Choose providedIn: &#39;root&#39; when services are stateless or shared.</li><li>Choose component providers when you need isolated state per component instance.</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=39f293e51385" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Understanding Dependency Injection: The What, Why, and How (With Angular Examples)]]></title>
            <link>https://medium.com/@AbdelrahmanAbdelatif/understanding-dependency-injection-the-what-why-and-how-with-angular-examples-2d1cb6101f86?source=rss-bfa31e9959bf------2</link>
            <guid isPermaLink="false">https://medium.com/p/2d1cb6101f86</guid>
            <dc:creator><![CDATA[Abdelrhman Abdelatif]]></dc:creator>
            <pubDate>Wed, 06 Aug 2025 18:19:07 GMT</pubDate>
            <atom:updated>2025-08-06T18:19:07.144Z</atom:updated>
            <content:encoded><![CDATA[<p>When building scalable front-end applications, <strong>clean architecture and maintainability</strong> are essential. One core concept that helps us achieve this is <strong>Dependency Injection (DI)</strong>.</p><p>Let’s explore what Dependency Injection is, <strong>why it matters</strong>, and <strong>how Angular makes it super easy to implement</strong>.</p><h3>What is Dependency Injection?</h3><p><strong><em>Dependency Injection (DI)</em></strong> is a design pattern where a class receives its dependencies from the <strong>outside</strong>, rather than creating them itself.</p><blockquote><em>In simple terms :<br> Instead of a class </em>creating<em> the objects it depends on, it is </em>given<em> those objects.</em></blockquote><p>This leads to:</p><ul><li><strong>Looser coupling</strong> between components</li><li><strong>Easier testing and mocking</strong></li><li><strong>Better code organization</strong></li></ul><h3>Why is DI Important?</h3><p>Let’s say you have a UserService that gets user data. Instead of hardcoding it inside a component, you <em>inject</em> it. This way:</p><ul><li>You can <strong>swap it easily</strong> for a mock during unit tests</li><li>You <strong>follow SOLID principles</strong> (especially the Dependency Inversion Principle)</li><li>Your code becomes <strong>more reusable and modular</strong></li></ul><h3>💡 DI in Angular: How it Works</h3><p>Angular has a powerful <strong>built-in Dependency Injection system</strong>. Here’s how it typically works:</p><ol><li>Create a Service</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*IGxxbpx1AVjaekpyizjbOQ.png" /></figure><p>2. Inject It Into a Component</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*zPytZAbsrd4XADebzVdLkA.png" /></figure><h3>What Happens Behind the Scenes?</h3><p>Angular uses an <strong>Injector Tree</strong> to keep track of all dependencies.</p><p>[ The <strong>Injector Tree</strong> is the internal system Angular uses to <strong>manage and provide dependencies (like services)</strong> throughout your application.It determines <strong>where and how Angular looks for a service</strong> when it needs to inject it into a component, directive, pipe, or another service. ]</p><p>{</p><ul><li>The <strong>Injector Tree</strong> is a hierarchy of injectors that Angular builds.</li><li>It follows the <strong>component hierarchy</strong>.</li><li>Angular starts searching for a dependency at the component’s injector and moves <strong>up</strong> the tree.</li><li>Services provided in the <strong>root injector</strong> are accessible anywhere.</li><li>You can scope services to specific modules/components by providing them locally.</li></ul><p>}</p><p>Services are <strong>registered</strong> via @Injectable and provided via providedIn or manually in providers: [].</p><p>When Angular sees a constructor that needs a service, it <strong>automatically resolves and injects</strong> the correct instance.</p><h3>Clean Code Benefits</h3><p>Less boilerplate code.<br> Encourages separation of concerns.<br> Easier to test components/services in isolation.<br> Reuse the same logic across multiple parts of the app.</p><p><strong><em>Dependency Injection(DI)</em></strong> is one of the reasons Angular apps scale so well. It encourages clean code, better testing, and modular design.</p><p>If you’re new to Angular, mastering DI is a great step toward building maintainable apps.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2d1cb6101f86" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>