<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Giorgio Galassi</title>
    <description>The latest articles on DEV Community by Giorgio Galassi (@ggalassi).</description>
    <link>https://dev.to/ggalassi</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1717803%2F759ae242-5db3-40d9-b13a-80ef26bcf1bc.jpeg</url>
      <title>DEV Community: Giorgio Galassi</title>
      <link>https://dev.to/ggalassi</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/ggalassi"/>
    <language>en</language>
    <item>
      <title>Angular v19+ — Understanding @defer: Blocks, Triggers, and Deferrable Views (Part 2) 🔥🚀</title>
      <dc:creator>Giorgio Galassi</dc:creator>
      <pubDate>Sun, 07 Dec 2025 10:12:11 +0000</pubDate>
      <link>https://dev.to/ggalassi/angular-v19-understanding-defer-blocks-triggers-and-deferrable-views-part-2-31kj</link>
      <guid>https://dev.to/ggalassi/angular-v19-understanding-defer-blocks-triggers-and-deferrable-views-part-2-31kj</guid>
      <description>&lt;p&gt;One of the main goals in modern Angular apps is reducing hydration costs and improving user experience. With Angular v19, we finally get native tools to achieve this: &lt;strong&gt;Incremental Hydration&lt;/strong&gt; and &lt;strong&gt;Event Replay&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;In &lt;a href="https://medium.com/@giorgio.galassi/angular-v18-understanding-defer-blocks-triggers-and-deferrable-views-part-1-5a5dfaf52cd2" rel="noopener noreferrer"&gt;Part 1&lt;/a&gt;, we explored the fundamentals of &lt;code&gt;@defer&lt;/code&gt; blocks and triggers. Now, let’s see how Angular extends that foundation to make hydration smarter and interactions smoother.&lt;/p&gt;




&lt;h3&gt;
  
  
  💧 Incremental Hydration
&lt;/h3&gt;

&lt;p&gt;Hydration is the process of transforming a pre-rendered HTML page (generated by server-side rendering) into a fully interactive Angular app on the client side.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://angular.dev/guide/incremental-hydration" rel="noopener noreferrer"&gt;&lt;strong&gt;Incremental Hydration&lt;/strong&gt;&lt;/a&gt; takes this a step further by letting you control &lt;em&gt;when&lt;/em&gt; specific parts of your application should become interactive.&lt;/p&gt;

&lt;p&gt;This means better &lt;a href="https://developers.google.com/search/docs/appearance/core-web-vitals?hl=en" rel="noopener noreferrer"&gt;&lt;strong&gt;Core Web Vitals&lt;/strong&gt;&lt;/a&gt;, faster &lt;strong&gt;initial paints&lt;/strong&gt;, and a smoother user experience overall.&lt;/p&gt;

&lt;p&gt;Activate it like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;appConfig&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;ApplicationConfig&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;providers&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
    &lt;span class="c1"&gt;// other providers&lt;/span&gt;
    &lt;span class="nf"&gt;provideClientHydration&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;withIncrementalHydration&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt;
  &lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Once configured, you can start deferring hydration for parts of your UI:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;@defer (hydrate on idle) {
  &lt;span class="nt"&gt;&amp;lt;large-cmp&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
} @placeholder {
  &lt;span class="nt"&gt;&amp;lt;div&amp;gt;&lt;/span&gt;Large component placeholder&lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The hydrate syntax mirrors the classic &lt;code&gt;@defer&lt;/code&gt; structure, supporting the same triggers and patterns. You can even combine behaviors:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;@defer (on idle; hydrate on interaction) {
  &lt;span class="nt"&gt;&amp;lt;large-cmp&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
} @placeholder {
  &lt;span class="nt"&gt;&amp;lt;div&amp;gt;&lt;/span&gt;Example Placeholder&lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; The &lt;code&gt;on interaction&lt;/code&gt; trigger behaves differently when used with &lt;code&gt;hydrate&lt;/code&gt;. Classic &lt;code&gt;@defer&lt;/code&gt; requires an element reference, while &lt;code&gt;hydrate&lt;/code&gt; doesn’t—the interaction happens directly with the de-hydrated version of the component.&lt;/p&gt;

&lt;p&gt;Example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="c"&gt;&amp;lt;!-- Classic @defer --&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;#greeting&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Hello!&lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;

@defer (on interaction(greeting)) {
  &lt;span class="nt"&gt;&amp;lt;greetings-cmp&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
}

&lt;span class="c"&gt;&amp;lt;!-- @defer with hydrate --&amp;gt;&lt;/span&gt;
@defer (hydrate on interaction) {
  &lt;span class="nt"&gt;&amp;lt;greetings-cmp&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;With &lt;code&gt;hydrate&lt;/code&gt;, the component itself is the trigger, simplifying setup and making it easier to use in real-world hydration scenarios.&lt;/p&gt;

&lt;h4&gt;
  
  
  Why it matters
&lt;/h4&gt;

&lt;p&gt;Incremental Hydration is especially valuable for large apps with multiple deferred views — dashboards, content-heavy pages, or e-commerce layouts. It helps you decide &lt;em&gt;when&lt;/em&gt; to activate interactivity, improving both &lt;strong&gt;performance&lt;/strong&gt; and &lt;strong&gt;responsiveness&lt;/strong&gt;.&lt;/p&gt;




&lt;h3&gt;
  
  
  ⚡ Event Replay
&lt;/h3&gt;

&lt;p&gt;Server-Side Rendering (SSR) is key for performance and SEO, but it introduces a common problem: &lt;strong&gt;lost interactions&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;When HTML is pre-rendered, users can start clicking before the JavaScript is fully hydrated. Without proper handling, those interactions are lost — leading to broken UX.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://angular.dev/guide/hydration#capturing-and-replaying-events" rel="noopener noreferrer"&gt;&lt;strong&gt;Event Replay&lt;/strong&gt;&lt;/a&gt; fixes this by capturing events during hydration and replaying them in the same order they occurred.&lt;/p&gt;

&lt;p&gt;This ensures every user action is processed, even if it happened before the app became interactive.&lt;/p&gt;

&lt;p&gt;Activate it with:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;appConfig&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;ApplicationConfig&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;providers&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
    &lt;span class="c1"&gt;// other providers&lt;/span&gt;
    &lt;span class="nf"&gt;provideClientHydration&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;withEventReplay&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt;
  &lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If you’re already using &lt;code&gt;withIncrementalHydration()&lt;/code&gt;, you don’t need to add &lt;code&gt;withEventReplay()&lt;/code&gt; separately—it’s included automatically.&lt;/p&gt;

&lt;h4&gt;
  
  
  Why it matters
&lt;/h4&gt;

&lt;p&gt;Event Replay ensures that &lt;strong&gt;no user action is lost&lt;/strong&gt;. It captures input events (like clicks, scrolls, or typing) and replays them after hydration. The result is a seamless, frustration-free experience for users.&lt;/p&gt;




&lt;h3&gt;
  
  
  🧩 Combined Example
&lt;/h3&gt;

&lt;p&gt;Here’s how both features can work together:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;appConfig&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;ApplicationConfig&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;providers&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
    &lt;span class="nf"&gt;provideClientHydration&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;withIncrementalHydration&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt;
  &lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;@defer (hydrate on interaction) {
  &lt;span class="nt"&gt;&amp;lt;user-profile&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
} @placeholder {
  &lt;span class="nt"&gt;&amp;lt;loading-spinner&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this example, Angular hydrates the &lt;code&gt;user-profile&lt;/code&gt; component only after the user interacts with its placeholder. Any clicks made before hydration are safely replayed, thanks to &lt;strong&gt;Event Replay&lt;/strong&gt;.&lt;/p&gt;




&lt;h3&gt;
  
  
  🧠 Behind the Scenes
&lt;/h3&gt;

&lt;p&gt;Under the hood:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Incremental Hydration&lt;/strong&gt; reuses the server-generated DOM and attaches event listeners lazily.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Event Replay&lt;/strong&gt; hooks into the browser’s event queue, caching early interactions and re-dispatching them once hydration is complete.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;These optimizations work together to provide a faster, more resilient user experience especially in apps with complex, interactive UIs.&lt;/p&gt;




&lt;h3&gt;
  
  
  🪄 Key Takeaways
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Incremental Hydration&lt;/strong&gt; lets you decide &lt;em&gt;when&lt;/em&gt; to make parts of your app interactive.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Event Replay&lt;/strong&gt; ensures &lt;em&gt;no interaction is lost&lt;/em&gt; during hydration.&lt;/li&gt;
&lt;li&gt;Combined, they improve &lt;strong&gt;Core Web Vitals&lt;/strong&gt;, reduce &lt;strong&gt;Time to Interactive&lt;/strong&gt;, and simplify performance optimization in Angular.&lt;/li&gt;
&lt;li&gt;👉 Try it live on &lt;a href="https://stackblitz.com/~/github.com/giorgiogalassi/defer" rel="noopener noreferrer"&gt;StackBlitz&lt;/a&gt; to see Incremental Hydration and Event Replay in action! &lt;strong&gt;Core Web Vitals&lt;/strong&gt;, reduce &lt;strong&gt;Time to Interactive&lt;/strong&gt;, and simplify performance optimization in Angular.&lt;/li&gt;
&lt;/ul&gt;




&lt;p&gt;If you found this helpful, follow me here and on &lt;a href="https://www.linkedin.com/in/giorgiogalassi/" rel="noopener noreferrer"&gt;&lt;strong&gt;LinkedIn&lt;/strong&gt;&lt;/a&gt; for more deep dives into Angular, web performance, and modern frontend development.&lt;/p&gt;

&lt;p&gt;See you in the next one! 🤙🏻&lt;br&gt;
— &lt;strong&gt;G&lt;/strong&gt;.&lt;/p&gt;

</description>
      <category>angular</category>
      <category>hydration</category>
      <category>incrementalhydration</category>
      <category>defer</category>
    </item>
    <item>
      <title>Angular v18+ — Understanding @defer: Blocks, Triggers, and Deferrable Views (Part 1) 🔥🚀</title>
      <dc:creator>Giorgio Galassi</dc:creator>
      <pubDate>Sun, 07 Dec 2025 10:02:30 +0000</pubDate>
      <link>https://dev.to/ggalassi/angular-v18-understanding-defer-blocks-triggers-and-deferrable-views-part-1-1m56</link>
      <guid>https://dev.to/ggalassi/angular-v18-understanding-defer-blocks-triggers-and-deferrable-views-part-1-1m56</guid>
      <description>&lt;p&gt;Angular v18 continues to introduce powerful new features, some aimed at simplifying development workflows, such as the &lt;a href="https://medium.com/@giorgio.galassi/angular-v18-introducing-let-a-new-way-to-declare-variables-and-do-logic-in-templates-8b3f4d196b23" rel="noopener noreferrer"&gt;&lt;code&gt;@let&lt;/code&gt;&lt;/a&gt; syntax, &lt;a href="https://medium.com/@giorgio.galassi/angular-v18-functional-redirection-using-redirectto-10c853d9d837" rel="noopener noreferrer"&gt;&lt;code&gt;redirectTo&lt;/code&gt;&lt;/a&gt; as a function, and &lt;a href="https://medium.com/@giorgio.galassi/angular-v18-ng-content-fallback-content-dd3d2c238373" rel="noopener noreferrer"&gt;&lt;code&gt;ng-content&lt;/code&gt;&lt;/a&gt; fallback content. Other functionalities, however, are designed to enhance application performance.&lt;/p&gt;

&lt;h3&gt;
  
  
  What is Angular’s &lt;code&gt;@defer&lt;/code&gt; Block?
&lt;/h3&gt;

&lt;p&gt;The &lt;code&gt;@defer&lt;/code&gt; block is part of Angular's newly introduced control-flow syntax family (&lt;code&gt;@if&lt;/code&gt;, &lt;code&gt;@for&lt;/code&gt;, &lt;code&gt;@switch&lt;/code&gt;, and more). This feature allows developers to delay the loading of specific elements until certain pre-determined triggers are met. These triggers can be selected from a predefined list or customized. You can also create a sequence of triggers to control exactly when the component is loaded.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;@defer {
  &lt;span class="nt"&gt;&amp;lt;my-very-heavy-component&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h3&gt;
  
  
  Why use Angular’s deferrable views for optimized performance?
&lt;/h3&gt;

&lt;p&gt;Deferrable views offer the advantage of significantly reducing the initial bundle size. By deferring a view, you can avoid loading a heavy component until it’s needed, improving both performance and user experience. For example, you might delay loading a component that becomes relevant later in the application’s flow.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; Not all components are deferrable. To use &lt;code&gt;@defer&lt;/code&gt;, a component must be standalone, and it's essential to avoid referencing it outside the &lt;code&gt;@defer&lt;/code&gt; block (e.g., using &lt;code&gt;@ViewChild&lt;/code&gt;).*&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Starting with &lt;a href="https://blog.angular.dev/the-future-is-standalone-475d7edbc706" rel="noopener noreferrer"&gt;Angular v19&lt;/a&gt;, newly created components will be standalone by default, meaning they will also be deferrable by default.&lt;/p&gt;
&lt;h3&gt;
  
  
  Exploring &lt;code&gt;@defer&lt;/code&gt; Blocks: Syntax and Usage
&lt;/h3&gt;

&lt;p&gt;This section breaks down the different &lt;code&gt;@defer&lt;/code&gt; sub-blocks:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;@placehodelr\&lt;/code&gt;&lt;/strong&gt;: Displays default content while the deferred component is loading.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;@loading\&lt;/code&gt;&lt;/strong&gt;: Shows a loading indicator while the deferred content is being fetched.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;@error\&lt;/code&gt;&lt;/strong&gt;: Displays a fallback message if the deferred content fails to load.&lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; All components, directives, or pipes used within any of these sub-blocks are &lt;strong&gt;eagerly loaded&lt;/strong&gt;.*&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h3&gt;
  
  
  How to Combine Multiple Triggers with &lt;code&gt;@defer&lt;/code&gt; in Angular v18
&lt;/h3&gt;

&lt;p&gt;Angular offers various triggers for controlling when deferred content is loaded:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;on idle&lt;/strong&gt;: Loads when the browser is idle; it’s the default trigger for the &lt;code&gt;@defer&lt;/code&gt; block.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;on viewport&lt;/strong&gt;: Loads when the content enters the viewport.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;on interaction&lt;/strong&gt;: Loads based on specific user interactions, such as clicks or form submissions.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;on hover&lt;/strong&gt;: Triggers when the user hovers over the element.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;on immediate&lt;/strong&gt;: Loads content immediately under specific conditions.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;on timer&lt;/strong&gt;: Loads after a specified time delay.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;when:&lt;/strong&gt; Specifies a condition as an expression that returns a boolean.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;You can also combine triggers to create complex loading scenarios, such as loading content when it enters the viewport or when the user hovers over it.&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="c"&gt;&amp;lt;!-- More than one `on` example --&amp;gt;&lt;/span&gt;
&lt;span class="c"&gt;&amp;lt;!-- Multiple on triggers are always `OR` conditions --&amp;gt;&lt;/span&gt;
@defer (on viewport; on timer(5s)) {
  &lt;span class="nt"&gt;&amp;lt;my-very-heavy-component&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
} @placeholder {
  &lt;span class="nt"&gt;&amp;lt;img&lt;/span&gt; &lt;span class="na"&gt;src=&lt;/span&gt;&lt;span class="s"&gt;"placeholder.png"&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
}

&lt;span class="c"&gt;&amp;lt;!-- Defer `when` example --&amp;gt;&lt;/span&gt;
@defer (when cond) {
  &lt;span class="nt"&gt;&amp;lt;my-very-heavy-component&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
}

&lt;span class="c"&gt;&amp;lt;!-- Defer `on` and `when` example --&amp;gt;&lt;/span&gt;
&lt;span class="c"&gt;&amp;lt;!-- `on` and `where` conditions are always `OR` conditions --&amp;gt;&lt;/span&gt;
@defer (on viewport; when cond) {
  &lt;span class="nt"&gt;&amp;lt;calendar-cmp&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
} @placeholder {
  &lt;span class="nt"&gt;&amp;lt;img&lt;/span&gt; &lt;span class="na"&gt;src=&lt;/span&gt;&lt;span class="s"&gt;"placeholder.png"&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h3&gt;
  
  
  Best Practices for Using &lt;code&gt;@defer&lt;/code&gt; in Angular v18: Tips and Considerations
&lt;/h3&gt;

&lt;p&gt;To use &lt;code&gt;@defer&lt;/code&gt; effectively, it’s essential to understand potential performance implications and optimize its usage:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Avoiding Layout Shifts&lt;/strong&gt;: Ensure that deferred components do not cause layout shifts that could impact the user experience.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Standalone Components Only&lt;/strong&gt;: Make sure components used with &lt;code&gt;@defer&lt;/code&gt; are standalone to avoid dependency conflicts.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Combining Triggers Wisely&lt;/strong&gt;: Use combinations of triggers strategically to maximize performance and user engagement.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3&gt;
  
  
  Nested &lt;code&gt;@defer&lt;/code&gt; Blocks
&lt;/h3&gt;

&lt;p&gt;It is possible to have nested &lt;code&gt;@defer&lt;/code&gt; blocks, with each block respecting and waiting for its own trigger. To prevent unexpected behavior, it is recommended to assign different triggers to each block, unless you intentionally want multiple blocks to respond to the same triggers.&lt;/p&gt;

&lt;p&gt;Below, you can find a StackBlitz project where you can explore nested &lt;code&gt;@defer&lt;/code&gt; blocks:&lt;/p&gt;

&lt;p&gt;

&lt;/p&gt;
&lt;div class="crayons-card c-embed text-styles text-styles--secondary"&gt;
    &lt;div class="c-embed__content"&gt;
      &lt;div class="c-embed__body flex items-center justify-between"&gt;
        &lt;a href="https://stackblitz.com/~/github.com/giorgiogalassi/defer?file=src%2Fmain.ts&amp;amp;amp;source=post_page-----5a5dfaf52cd2---------------------------------------" rel="noopener noreferrer" class="c-link fw-bold flex items-center"&gt;
          &lt;span class="mr-2"&gt;stackblitz.com&lt;/span&gt;
          

        &lt;/a&gt;
      &lt;/div&gt;
    &lt;/div&gt;
&lt;/div&gt;





&lt;p&gt;At the time of this article’s publication, the StackBlitz contains examples of:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;code&gt;on interaction&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;on viewport&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;Nested &lt;code&gt;@defer&lt;/code&gt; blocks&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;To observe the deferred loading in action, open the network tab in your browser’s developer tools and filter by JavaScript (JS) to see only the downloaded files. Experiment with the application, and you will notice different chunks of components being loaded in a deferred manner.&lt;/p&gt;

&lt;h3&gt;
  
  
  Conclusion
&lt;/h3&gt;

&lt;p&gt;Starting with Angular v18, the &lt;code&gt;@defer&lt;/code&gt; feature provides a powerful way to optimize your application’s loading strategy. By leveraging triggers and fallback blocks (&lt;code&gt;@placeholder&lt;/code&gt;, &lt;code&gt;@loading&lt;/code&gt;, &lt;code&gt;@error&lt;/code&gt;), you can create efficient, user-friendly experiences.&lt;/p&gt;

&lt;p&gt;Adopting a “deferrable-first” mindset is both useful and important, as it allows us to deliver smoother user experiences, thanks in part to a lighter bundle.&lt;/p&gt;

&lt;p&gt;Future articles will dive deeper into advanced &lt;code&gt;@defer&lt;/code&gt; usage and its integration with other Angular features, so stay tuned!&lt;/p&gt;

&lt;h3&gt;
  
  
  Next steps
&lt;/h3&gt;

&lt;h4&gt;
  
  
  &lt;strong&gt;Prefetching&lt;/strong&gt;
&lt;/h4&gt;

&lt;p&gt;The &lt;code&gt;@defer&lt;/code&gt; block also supports configuration for pre-fetching components. &lt;a href="https://developer.mozilla.org/en-US/docs/Glossary/Prefetch" rel="noopener noreferrer"&gt;Prefetching&lt;/a&gt; is a process where we anticipate where the user might navigate after a specific action and begin loading resources that could be needed. In Angular, this can be achieved using the &lt;code&gt;@defer&lt;/code&gt; block. The prefetch syntax works similarly to main &lt;code&gt;@defer&lt;/code&gt; conditions; &lt;code&gt;when&lt;/code&gt; and/or &lt;code&gt;on&lt;/code&gt; can be used to declare different triggers.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;@defer (on interaction; prefetch on idle) {
  &lt;span class="nt"&gt;&amp;lt;calendar-cmp&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
} @placeholder {
  &lt;span class="nt"&gt;&amp;lt;img&lt;/span&gt; &lt;span class="na"&gt;src=&lt;/span&gt;&lt;span class="s"&gt;"placeholder.png"&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  &lt;strong&gt;Incremental Hydration&lt;/strong&gt;
&lt;/h4&gt;

&lt;p&gt;Hydration transforms a pre-rendered HTML page (produced by server-side rendering) into a fully interactive Angular application on the client side. With &lt;a href="https://www.youtube.com/watch?v=I4n1IcZ3vRs" rel="noopener noreferrer"&gt;incremental hydration&lt;/a&gt; (&lt;a href="https://github.com/angular/angular/discussions/57664" rel="noopener noreferrer"&gt;here&lt;/a&gt; the complete RFC), you can determine when specific parts of your application need to become interactive.&lt;/p&gt;

&lt;p&gt;This helps improve &lt;a href="https://developers.google.com/search/docs/appearance/core-web-vitals?hl=it" rel="noopener noreferrer"&gt;Core Web Vitals&lt;/a&gt; and provides a faster initial paint with better performance for the end-user.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="c"&gt;&amp;lt;!-- Hydrate `when` example --&amp;gt;&lt;/span&gt;
@defer (hydrate when user() !== null){
  &lt;span class="nt"&gt;&amp;lt;some-cmp&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
}

&lt;span class="c"&gt;&amp;lt;!-- Hydrate `on` example --&amp;gt;&lt;/span&gt;
@defer (hydrate on interaction) {
  &lt;span class="nt"&gt;&amp;lt;some-cmp&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
}

&lt;span class="c"&gt;&amp;lt;!-- Defer plus Hydrate `on` example --&amp;gt;&lt;/span&gt;
@defer (on viewport; hydrate on interaction) {
  &lt;span class="nt"&gt;&amp;lt;some-cmp&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;p&gt;If you found this helpful, follow me here and on &lt;a href="https://www.linkedin.com/in/giorgiogalassi/" rel="noopener noreferrer"&gt;&lt;strong&gt;LinkedIn&lt;/strong&gt;&lt;/a&gt; for more deep dives into Angular, web performance, and modern frontend development.&lt;/p&gt;

&lt;p&gt;See you in the next one! 🤙🏻&lt;br&gt;
— &lt;strong&gt;G&lt;/strong&gt;.&lt;/p&gt;

</description>
      <category>angular</category>
      <category>incrementalhydration</category>
      <category>defer</category>
      <category>prefetch</category>
    </item>
    <item>
      <title>Angular v19+ — computed vs linkedSignal signals 🔥🚀</title>
      <dc:creator>Giorgio Galassi</dc:creator>
      <pubDate>Sun, 07 Dec 2025 09:53:01 +0000</pubDate>
      <link>https://dev.to/ggalassi/angular-v19-computed-vs-linkedsignal-signals-27o7</link>
      <guid>https://dev.to/ggalassi/angular-v19-computed-vs-linkedsignal-signals-27o7</guid>
      <description>&lt;p&gt;Angular’s move toward a signal‑first ecosystem didn’t end with &lt;a href="https://medium.com/@giorgio.galassi/angular-v19-understanding-the-new-resource-and-rxresource-apis-8a387c7d9351" rel="noopener noreferrer"&gt;&lt;code&gt;resource()&lt;/code&gt;&lt;/a&gt;&lt;a href="https://medium.com/@giorgio.galassi/angular-v19-understanding-the-new-resource-and-rxresource-apis-8a387c7d9351" rel="noopener noreferrer"&gt;, &lt;/a&gt;&lt;a href="https://medium.com/@giorgio.galassi/angular-v19-understanding-the-new-resource-and-rxresource-apis-8a387c7d9351" rel="noopener noreferrer"&gt;&lt;code&gt;rxResource()&lt;/code&gt;&lt;/a&gt; or &lt;a href="https://medium.com/@giorgio.galassi/angular-v19-understanding-the-new-httpresource-api-837e1dadc990" rel="noopener noreferrer"&gt;&lt;code&gt;httpResource()&lt;/code&gt;&lt;/a&gt;. Those primitives made async flows cleaner, but they also exposed a deeper shift: the way we model state is changing. When you start structuring components around signals, two primitives quickly become the backbone of state organization: &lt;a href="https://angular.dev/guide/signals#computed-signals" rel="noopener noreferrer"&gt;&lt;strong&gt;computed&lt;/strong&gt;&lt;/a&gt; and &lt;a href="https://angular.dev/guide/signals/linked-signal" rel="noopener noreferrer"&gt;&lt;strong&gt;linkedSignal&lt;/strong&gt;&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;At a glance they seem similar, but they solve very different problems. One focuses on pure derivation. The other acts as a controlled bridge between component state and something external. Understanding the difference is key to avoiding subtle bugs.&lt;/p&gt;




&lt;h3&gt;
  
  
  🔧 Signals in Angular — a quick recap
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;signal&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;computed&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;@angular/core&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;count&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;signal&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;double&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;computed&lt;/span&gt;&lt;span class="p"&gt;(()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nf"&gt;count&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;A &lt;code&gt;signal&lt;/code&gt; stores writable state. A &lt;code&gt;computed&lt;/code&gt; value is automatically recalculated whenever its dependencies change. You never set it manually, and it shouldn’t perform side effects. It’s a clean, predictable way to model values that depend entirely on other signals.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;linkedSignal&lt;/code&gt; builds on this mechanism but shifts the focus: instead of deriving values, it synchronizes state with a source that lives outside the local signal graph.&lt;/p&gt;




&lt;h3&gt;
  
  
  📐 What computed actually does
&lt;/h3&gt;

&lt;p&gt;A &lt;code&gt;computed&lt;/code&gt; value is nothing more than a function of other signals. Its job is to keep a derived value always in sync with its inputs. You give it the signals it depends on, and Angular takes care of the rest.&lt;/p&gt;

&lt;p&gt;For example, if you have two form fields and want a combined value and a quick validity check, a &lt;code&gt;computed&lt;/code&gt; is exactly the right tool:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;firstName&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;signal&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;''&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;lastName&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;signal&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;''&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;fullName&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;computed&lt;/span&gt;&lt;span class="p"&gt;(()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nf"&gt;firstName&lt;/span&gt;&lt;span class="p"&gt;()}&lt;/span&gt;&lt;span class="s2"&gt; &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nf"&gt;lastName&lt;/span&gt;&lt;span class="p"&gt;()}&lt;/span&gt;&lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;trim&lt;/span&gt;&lt;span class="p"&gt;());&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;isValid&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;computed&lt;/span&gt;&lt;span class="p"&gt;(()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nf"&gt;fullName&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;&lt;span class="nx"&gt;length&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here everything is deterministic: every value can be recalculated at any time from the source signals. You never push data back, and nothing lives outside the model. As long as your flow is one‑way, state that drives other state, &lt;code&gt;computed&lt;/code&gt; is the cleanest and simplest option.&lt;/p&gt;

&lt;p&gt;Where it falls short is when you need to mirror or update something that doesn’t originate inside the component. For that, it’s the wrong tool.&lt;/p&gt;




&lt;h3&gt;
  
  
  🔗 Why linkedSignal exists
&lt;/h3&gt;

&lt;p&gt;Some state relationships require a value to reset reactively when its source changes while still remaining fully writable by the user. A &lt;code&gt;computed&lt;/code&gt; can handle the reactive reset but cannot be written to. A plain &lt;code&gt;signal&lt;/code&gt; can be written to, but it cannot reactively recalculate itself from a source. &lt;code&gt;linkedSignal&lt;/code&gt; fills this exact gap.&lt;/p&gt;

&lt;p&gt;Instead of wiring effects to manually reset values, a pattern that becomes noisy and risks unintended write loops, &lt;code&gt;linkedSignal&lt;/code&gt; expresses the relationship declaratively: &lt;em&gt;“derive from this source unless the user overrides it.”&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Under the hood, &lt;code&gt;linkedSignal&lt;/code&gt; listens to the source and recalculates its value whenever that source changes.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;🔍 &lt;strong&gt;Note:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The &lt;code&gt;computation&lt;/code&gt; function receives two arguments: the new source value and a &lt;code&gt;previous&lt;/code&gt; object. &lt;code&gt;previous.source&lt;/code&gt; holds the source value before the update, while &lt;code&gt;previous.value&lt;/code&gt; contains the previous &lt;em&gt;&lt;code&gt;linkedSignal&lt;/code&gt;&lt;/em&gt; value, including user overrides. This allows you to implement simple resets, conditional resets, or more advanced transition rules based on both old and new state.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;In parallel, the linked signal continues to expose the usual writable signal API (&lt;code&gt;set&lt;/code&gt;, &lt;code&gt;update&lt;/code&gt;), so user overrides remain straightforward.&lt;/p&gt;




&lt;h3&gt;
  
  
  🧪 Two practical examples
&lt;/h3&gt;

&lt;h3&gt;
  
  
  Pure derived state — computed
&lt;/h3&gt;

&lt;p&gt;If a value can always be derived directly from its inputs and never needs manual intervention, a &lt;code&gt;computed&lt;/code&gt; is the simplest fit. Filtering a list based on user input is a classic example where nothing external is involved and no override is necessary.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;items&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;signal&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="kr"&gt;string&lt;/span&gt;&lt;span class="p"&gt;[]&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;([&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Angular&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;React&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Vue&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;]);&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;filter&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;signal&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;a&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;filteredItems&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;computed&lt;/span&gt;&lt;span class="p"&gt;(()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt;
  &lt;span class="nf"&gt;items&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;&lt;span class="nf"&gt;filter&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;item&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;item&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;toLowerCase&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;&lt;span class="nf"&gt;includes&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;filter&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;&lt;span class="nf"&gt;toLowerCase&lt;/span&gt;&lt;span class="p"&gt;()))&lt;/span&gt;
&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Reactive default with user override — linkedSignal
&lt;/h3&gt;

&lt;p&gt;A more nuanced scenario is when the value depends on another piece of state but must still allow direct user edits. Consider an app with a theme selector and a user‑adjustable contrast slider.&lt;/p&gt;

&lt;p&gt;The contrast should reset to the optimal default whenever the theme changes, &lt;strong&gt;but&lt;/strong&gt; the user must be able to override that value afterward.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// The source signal&lt;/span&gt;
&lt;span class="nx"&gt;selectedTheme&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;signal&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;light&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;dark&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;light&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="c1"&gt;// Linked signal that recomputes when the theme changes&lt;/span&gt;
&lt;span class="nx"&gt;contrastLevel&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;linkedSignal&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;light&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;dark&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kr"&gt;number&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
  &lt;span class="na"&gt;source&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;selectedTheme&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;computation&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;newTheme&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;// Default contrast for dark theme&lt;/span&gt;
    &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;newTheme&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;dark&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="mi"&gt;80&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; 
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="mi"&gt;50&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// Default contrast for light theme&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;

&lt;span class="c1"&gt;// User interaction and manual override&lt;/span&gt;
&lt;span class="nf"&gt;onContrastChanged&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;newContrast&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;number&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;contrastLevel&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;set&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;newContrast&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this setup, &lt;code&gt;linkedSignal&lt;/code&gt; makes the relationship explicit and predictable. When the theme changes, &lt;code&gt;contrastLevel&lt;/code&gt; recomputes based on the new theme. When the user adjusts the value, the override takes priority. This avoids side‑effect‑driven resets and keeps the logic clean and declarative.&lt;/p&gt;

&lt;h3&gt;
  
  
  🧠 How to reason about the two
&lt;/h3&gt;

&lt;p&gt;The difference is straightforward once you think in terms of data direction.&lt;/p&gt;

&lt;p&gt;A &lt;code&gt;computed&lt;/code&gt; value is one‑way. Data flows from your signals into the computed output. There’s no feedback loop and no external synchronization.&lt;/p&gt;

&lt;p&gt;A &lt;code&gt;linkedSignal&lt;/code&gt; is two‑way. It sits between your component and another system. Reading it pulls in the current external value, while updating it pushes data out.&lt;/p&gt;

&lt;p&gt;Whenever you need writable state that remains aligned with an external layer, &lt;code&gt;linkedSignal&lt;/code&gt; is the right choice.&lt;/p&gt;




&lt;h3&gt;
  
  
  🎯 Picking the right tool
&lt;/h3&gt;

&lt;p&gt;Use a &lt;code&gt;computed&lt;/code&gt; when the value is entirely derived from other signals and doesn’t need to be written manually. It’s ideal for internal one‑direction flows within a component.&lt;/p&gt;

&lt;p&gt;Use a &lt;code&gt;linkedSignal&lt;/code&gt; when the component must expose a writable signal that represents an external state and must stay synchronized with it. This applies to inputs, stores, and any layer where the source of truth lives outside the component.&lt;/p&gt;

&lt;p&gt;When you’re unsure, start with &lt;code&gt;computed&lt;/code&gt;. If you later realize you’re wiring manual read‑and‑write glue between the component and external state, that’s usually the moment when switching to &lt;code&gt;linkedSignal&lt;/code&gt; cleans everything up.&lt;/p&gt;




&lt;h3&gt;
  
  
  ✨ Closing thoughts
&lt;/h3&gt;

&lt;p&gt;&lt;code&gt;computed&lt;/code&gt; and &lt;code&gt;linkedSignal&lt;/code&gt; address distinct needs. The first keeps derived values predictable and local. The second gives you a structured way to mirror and update external state without abandoning the signal mindset.&lt;/p&gt;

&lt;p&gt;Most of your application logic will rely on &lt;code&gt;signal&lt;/code&gt; and &lt;code&gt;computed&lt;/code&gt;. Reach for &lt;code&gt;linkedSignal&lt;/code&gt; only when synchronization with something external is required.&lt;/p&gt;




&lt;p&gt;If you found this helpful, follow me here and on &lt;a href="https://www.linkedin.com/in/giorgiogalassi/" rel="noopener noreferrer"&gt;&lt;strong&gt;LinkedIn&lt;/strong&gt;&lt;/a&gt; for more deep dives into Angular, web performance, and modern frontend development.&lt;/p&gt;

&lt;p&gt;See you in the next one! 🤙🏻&lt;br&gt;
 — &lt;strong&gt;G&lt;/strong&gt;.&lt;/p&gt;

</description>
      <category>angular</category>
      <category>linkedsignal</category>
      <category>signal</category>
      <category>computed</category>
    </item>
    <item>
      <title>Angular v18+ — Introducing @let syntax: A New Way to Declare Variables and do Logic in Templates 🔥🚀</title>
      <dc:creator>Giorgio Galassi</dc:creator>
      <pubDate>Fri, 21 Mar 2025 10:50:03 +0000</pubDate>
      <link>https://dev.to/ggalassi/angular-v18-introducing-let-syntax-a-new-way-to-declare-variables-and-do-logic-in-templates-3k1i</link>
      <guid>https://dev.to/ggalassi/angular-v18-introducing-let-syntax-a-new-way-to-declare-variables-and-do-logic-in-templates-3k1i</guid>
      <description>&lt;p&gt;Here we are again with another article that dives into the new features of &lt;strong&gt;&lt;em&gt;Angular v18&lt;/em&gt;&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;In this article, you will explore, understand the pros and cons, and learn how to use the new &lt;code&gt;@let&lt;/code&gt; template syntax. This powerful feature comes with great responsibility, as Uncle Ben would say.&lt;/p&gt;

&lt;h2&gt;
  
  
  🧠 What’s &lt;code&gt;@let&lt;/code&gt; syntax?
&lt;/h2&gt;

&lt;p&gt;As TypeScript developers, we are familiar with creating variables using &lt;code&gt;var&lt;/code&gt;, &lt;code&gt;const&lt;/code&gt;, and &lt;code&gt;let&lt;/code&gt;. In this scenario, &lt;code&gt;@let&lt;/code&gt; works similarly, but with one key difference: you can now create variables directly at the template level.&lt;/p&gt;

&lt;h2&gt;
  
  
  💡 How to use the &lt;code&gt;@let&lt;/code&gt; Syntax in Angular?
&lt;/h2&gt;

&lt;p&gt;Nothing is better to see some code in order to understand something.&lt;/p&gt;

&lt;p&gt;Let’s see a basic example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;@let name = 'Giorgio';

&lt;span class="nt"&gt;&amp;lt;label&amp;gt;&lt;/span&gt;{{ name }}&lt;span class="nt"&gt;&amp;lt;/label&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;As you might expect, the content of the variable will be rendered correctly:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;label&amp;gt;&lt;/span&gt;Giorgio&lt;span class="nt"&gt;&amp;lt;/label&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This opens up many new ways to handle our code, allowing us to move some logic directly within the template itself. With &lt;code&gt;@let&lt;/code&gt;, you can declare variables and use them throughout your template.&lt;/p&gt;

&lt;h2&gt;
  
  
  🔍 Advanced usage of &lt;code&gt;@let&lt;/code&gt;
&lt;/h2&gt;

&lt;p&gt;Of course, the power of &lt;code&gt;@let&lt;/code&gt; does not stop here. You can also perform conditional logic:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;@let isAuth = authService.isAuth();
@let username = authService.getUsername();

@let message = isAuth ? 'Welcome, ' + username + '!' : 'Welcome Anonymus!'

&lt;span class="nt"&gt;&amp;lt;label&amp;gt;&lt;/span&gt;{{ message }}&lt;span class="nt"&gt;&amp;lt;/label&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;From this simple example, you can already see how much cleaner our code can be. Let’s take it a step further.&lt;/p&gt;

&lt;h2&gt;
  
  
  🧮 Working with Arrays
&lt;/h2&gt;

&lt;p&gt;Sometimes you want to map or filter your arrays. Generally, you would write a function for that, save the output within the &lt;strong&gt;&lt;em&gt;TypeScript&lt;/em&gt;&lt;/strong&gt; file, and use it in the template. Now, you can do it as follows:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;@let onlineUsers = users.filter(({ status }) =&amp;gt; status === 'online');

@for(user of onlineUsers; track user.id) {
  &lt;span class="nt"&gt;&amp;lt;label&amp;gt;&lt;/span&gt;{{ user.name }} {{ user.surname }}&lt;span class="nt"&gt;&amp;lt;/label&amp;gt;&lt;/span&gt;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  🔄 Working with the Angular Async Pipe
&lt;/h2&gt;

&lt;p&gt;If you’ve worked with Angular, you’ve likely used the &lt;code&gt;async&lt;/code&gt; pipe. Here's how you can combine it with &lt;code&gt;@let&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;@let user = user$ | async;

&lt;span class="nt"&gt;&amp;lt;per&amp;gt;&lt;/span&gt;{{ user | json }}&lt;span class="nt"&gt;&amp;lt;/pre&amp;gt;&lt;/span&gt;

@let userPosts = user.posts || [];

@for(post of userPosts; track post.id) {
  &lt;span class="nt"&gt;&amp;lt;label&amp;gt;&lt;/span&gt;{{ post.title }}&lt;span class="nt"&gt;&amp;lt;/label&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;p&amp;gt;&lt;/span&gt;{{ post.content }}&lt;span class="nt"&gt;&amp;lt;/p&amp;gt;&lt;/span&gt;
} @empty {
  &lt;span class="nt"&gt;&amp;lt;label&amp;gt;&lt;/span&gt;No post to show!&lt;span class="nt"&gt;&amp;lt;/label&amp;gt;&lt;/span&gt;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this example, &lt;code&gt;@let&lt;/code&gt; is used to handle asynchronous data and iterate over user posts. The code is cleaner and keeps the logic within the template, reducing the need for additional component code.&lt;/p&gt;

&lt;p&gt;However, be careful when using &lt;code&gt;@let&lt;/code&gt; in combination with the &lt;code&gt;async&lt;/code&gt; pipe, as it may cause some performance issues.&lt;/p&gt;

&lt;p&gt;To avoid this, declare a variable to handle the subscription and use that variable wherever needed, as shown in the example above.&lt;/p&gt;

&lt;p&gt;This approach ensures a single subscription and avoids multiple re-evaluations, which can improve performance.&lt;/p&gt;

&lt;h2&gt;
  
  
  ✅ Conclusions
&lt;/h2&gt;

&lt;p&gt;The &lt;code&gt;@let&lt;/code&gt; syntax in Angular v18 offers a powerful way to declare variables and handle logic directly in templates. It simplifies the code and enhances readability, making it easier to manage dynamic and conditional content. However, with great power comes great responsibility, so use it wisely to keep your templates clean and maintainable.&lt;/p&gt;




&lt;p&gt;Thank you for staying with me, and I hope everything was clear. Feel free to explore more of my articles and &lt;a href="https://www.linkedin.com/in/giorgiogalassi/" rel="noopener noreferrer"&gt;&lt;strong&gt;follow me on LinkedIn!&lt;/strong&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;See you in the next one!&lt;/p&gt;

&lt;p&gt;Best, G.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Angular v19+ — Understanding the New httpResource() API 🔥🚀</title>
      <dc:creator>Giorgio Galassi</dc:creator>
      <pubDate>Thu, 20 Mar 2025 10:50:11 +0000</pubDate>
      <link>https://dev.to/ggalassi/angular-v19-understanding-the-new-httpresource-api-23h</link>
      <guid>https://dev.to/ggalassi/angular-v19-understanding-the-new-httpresource-api-23h</guid>
      <description>&lt;p&gt;&lt;a href="https://blog.angular.dev/angular-19-2-is-now-available-673ec70aea12" rel="noopener noreferrer"&gt;Angular v19.2&lt;/a&gt; is here, bringing yet another set of features designed to simplify our development experience.&lt;/p&gt;

&lt;p&gt;This time, the spotlight is on the &lt;strong&gt;new &lt;code&gt;httpResource()&lt;/code&gt; API&lt;/strong&gt;, which joins the resource family, alongside &lt;code&gt;resource()&lt;/code&gt; and &lt;code&gt;rxResource()&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;We previously explored these APIs in another article that you can find below:&lt;/p&gt;


&lt;div class="ltag__link"&gt;
  &lt;a href="/ggalassi" class="ltag__link__link"&gt;
    &lt;div class="ltag__link__pic"&gt;
      &lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1717803%2F759ae242-5db3-40d9-b13a-80ef26bcf1bc.jpeg" alt="ggalassi"&gt;
    &lt;/div&gt;
  &lt;/a&gt;
  &lt;a href="https://dev.to/ggalassi/angular-v19-understanding-the-new-resource-and-rxresource-apis-3393" class="ltag__link__link"&gt;
    &lt;div class="ltag__link__content"&gt;
      &lt;h2&gt;Angular v19+ — Understanding the New resource() and rxResource() APIs 🔥🚀&lt;/h2&gt;
      &lt;h3&gt;Giorgio Galassi ・ Mar 20&lt;/h3&gt;
      &lt;div class="ltag__link__taglist"&gt;
        &lt;span class="ltag__link__tag"&gt;#typescript&lt;/span&gt;
        &lt;span class="ltag__link__tag"&gt;#angular&lt;/span&gt;
        &lt;span class="ltag__link__tag"&gt;#resource&lt;/span&gt;
        &lt;span class="ltag__link__tag"&gt;#http&lt;/span&gt;
      &lt;/div&gt;
    &lt;/div&gt;
  &lt;/a&gt;
&lt;/div&gt;


&lt;h2&gt;
  
  
  ❓How Does It Work?
&lt;/h2&gt;

&lt;p&gt;Let’s first take a look at how the &lt;code&gt;rxResource()&lt;/code&gt; API is typically used to perform a backend call:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;rxResource&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;@angular/core/rxjs-interop&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="nx"&gt;rxUsers&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;rxResource&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;User&lt;/span&gt;&lt;span class="p"&gt;[],&lt;/span&gt; &lt;span class="kr"&gt;string&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="kc"&gt;undefined&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
  &lt;span class="na"&gt;request&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;query&lt;/span&gt;&lt;span class="p"&gt;(),&lt;/span&gt;
  &lt;span class="na"&gt;loader&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="nx"&gt;request&lt;/span&gt; &lt;span class="p"&gt;})&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt;
    &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="err"&gt;#&lt;/span&gt;&lt;span class="nx"&gt;http&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="kd"&gt;get&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;users&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;User&lt;/span&gt;&lt;span class="p"&gt;[]&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;API_URL&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;/search?q=&lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;request&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;pipe&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
      &lt;span class="nf"&gt;distinctUntilChanged&lt;/span&gt;&lt;span class="p"&gt;(),&lt;/span&gt;
      &lt;span class="nf"&gt;map&lt;/span&gt;&lt;span class="p"&gt;(({&lt;/span&gt; &lt;span class="nx"&gt;users&lt;/span&gt; &lt;span class="p"&gt;})&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;users&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
      &lt;span class="nf"&gt;catchError&lt;/span&gt;&lt;span class="p"&gt;(()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;throw&lt;/span&gt; &lt;span class="nc"&gt;Error&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Unable to load!&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
      &lt;span class="p"&gt;})&lt;/span&gt;
    &lt;span class="p"&gt;),&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;In this example, we still rely on &lt;strong&gt;&lt;code&gt;HttpClient&lt;/code&gt;&lt;/strong&gt;, and the &lt;code&gt;.get()&lt;/code&gt; method returns an &lt;strong&gt;&lt;code&gt;Observable&lt;/code&gt;&lt;/strong&gt;, which we process using &lt;strong&gt;&lt;code&gt;RxJS operators&lt;/code&gt;&lt;/strong&gt; like &lt;code&gt;map()&lt;/code&gt; and &lt;code&gt;catchError()&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;✅ &lt;strong&gt;Nothing is wrong with this approach&lt;/strong&gt;, but what if we wanted a &lt;strong&gt;simpler API&lt;/strong&gt; that integrates directly with HttpClient and eliminates the need to manually handle Observables?&lt;/p&gt;
&lt;h2&gt;
  
  
  🚀 Exploring &lt;code&gt;httpResource()&lt;/code&gt;
&lt;/h2&gt;

&lt;p&gt;Since &lt;code&gt;httpResource()&lt;/code&gt; is &lt;strong&gt;built directly on top of &lt;code&gt;HttpClient&lt;/code&gt;&lt;/strong&gt;, we no longer need to manually handle API requests.&lt;/p&gt;

&lt;p&gt;Instead, we can simply pass the API &lt;strong&gt;URL as a parameter&lt;/strong&gt;:&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;httpResource&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;@angular/common/http&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="nx"&gt;httpUsers&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;httpResource&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;User&lt;/span&gt;&lt;span class="p"&gt;[]&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;API_URL&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;With just &lt;strong&gt;this single line of code&lt;/strong&gt;, &lt;strong&gt;&lt;code&gt;httpResource()&lt;/code&gt;&lt;/strong&gt; automatically &lt;strong&gt;manages the request logic&lt;/strong&gt;, leveraging Angular's &lt;code&gt;HttpClient&lt;/code&gt; behind the scenes.&lt;/p&gt;

&lt;p&gt;✅ &lt;strong&gt;But what if we need more flexibility?&lt;/strong&gt;&lt;br&gt;
Real-world applications often require:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Setting &lt;strong&gt;default values&lt;/strong&gt; to prevent UI issues.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Parsing API responses&lt;/strong&gt; before assigning them to the Signal.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Let’s explore how &lt;code&gt;httpResource()&lt;/code&gt; handles this next.&lt;/p&gt;
&lt;h2&gt;
  
  
  📌 &lt;strong&gt;Using&lt;/strong&gt; &lt;code&gt;defaultValue&lt;/code&gt; and &lt;code&gt;parse&lt;/code&gt; &lt;strong&gt;for Safer Data Handling&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;By default, httpResource() expects valid data from the API. However, in real-world scenarios, we might need to:&lt;/p&gt;

&lt;p&gt;✅ Ensure a &lt;strong&gt;default value&lt;/strong&gt; when the API returns null or undefined.&lt;br&gt;
✅ &lt;strong&gt;Validate and parse&lt;/strong&gt; responses before assigning them to the signal.&lt;/p&gt;

&lt;p&gt;Using &lt;strong&gt;Zod&lt;/strong&gt; for schema validation, we can enforce &lt;strong&gt;type safety&lt;/strong&gt; directly within &lt;code&gt;httpResource()&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;httpResource&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;@angular/common/http&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;z&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;zod&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="c1"&gt;// Define a schema using Zod&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;UserSchema&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;z&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;object&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;z&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;string&lt;/span&gt;&lt;span class="p"&gt;(),&lt;/span&gt; &lt;span class="na"&gt;surname&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;z&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;string&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;});&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;UserResultsSchema&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;z&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;array&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;UserSchema&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="kd"&gt;type&lt;/span&gt; &lt;span class="nx"&gt;User&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;z&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;infer&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;typeof&lt;/span&gt; &lt;span class="nx"&gt;UserSchema&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="nx"&gt;httpUsers&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;httpResource&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;User&lt;/span&gt;&lt;span class="p"&gt;[]&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
  &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;API_URL&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;/search?q=&lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;query&lt;/span&gt;&lt;span class="p"&gt;()}&lt;/span&gt;&lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;defaultValue&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[],&lt;/span&gt; &lt;span class="c1"&gt;// Ensures an empty array if no data is returned&lt;/span&gt;
    &lt;span class="na"&gt;parse&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;UserResultsSchema&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;parse&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;// Validates and parses the API response&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;✅ &lt;strong&gt;Why is this useful?&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Prevents UI errors&lt;/strong&gt; from unexpected null values.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Ensures type safety&lt;/strong&gt; by validating API responses.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Eliminates extra validation logic&lt;/strong&gt; in the component&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;
  
  
  🔍 Advanced Use Case
&lt;/h2&gt;

&lt;p&gt;Passing just the &lt;strong&gt;API URL&lt;/strong&gt; is often &lt;strong&gt;not enough&lt;/strong&gt;. In our &lt;code&gt;rxResource()&lt;/code&gt; example, we included a &lt;strong&gt;search query parameter&lt;/strong&gt; tied to the &lt;code&gt;query()&lt;/code&gt; signal. Let’s explore how to achieve the &lt;strong&gt;same behavior&lt;/strong&gt; using the &lt;code&gt;httpResource()&lt;/code&gt; API:&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;httpResource&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;@angular/common/http&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="nx"&gt;httpUsers&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;httpResource&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;User&lt;/span&gt;&lt;span class="p"&gt;[]&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;(()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;API_URL&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;/search?q=&lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;query&lt;/span&gt;&lt;span class="p"&gt;()}&lt;/span&gt;&lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;By passing a &lt;strong&gt;reactive function&lt;/strong&gt; to &lt;code&gt;httpResource()&lt;/code&gt;, the API &lt;strong&gt;automatically listens&lt;/strong&gt; for changes in the &lt;code&gt;query&lt;/code&gt; signal.&lt;br&gt;
&lt;strong&gt;Every time &lt;code&gt;query()&lt;/code&gt; updates, a new request is triggered, ensuring that the latest data is always fetched&lt;/strong&gt;.&lt;/p&gt;


&lt;h2&gt;
  
  
  ⚠️ Important Considerations
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Each new API request cancels the previous one&lt;/strong&gt;, similar to how the &lt;code&gt;switchMap&lt;/code&gt; operator works in RxJS.&lt;br&gt;
This is the &lt;strong&gt;default behavior&lt;/strong&gt; of &lt;code&gt;httpResource()&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Be cautious when using this API for updates&lt;/strong&gt; (PUT, POST, DELETE requests).&lt;br&gt;
A subsequent update &lt;strong&gt;could cancel a previous request&lt;/strong&gt; before it completes, &lt;strong&gt;leading to potential data loss&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;❌ &lt;strong&gt;Avoid using &lt;code&gt;httpResource()&lt;/code&gt; for mutations&lt;/strong&gt;&lt;br&gt;
✔️ &lt;strong&gt;Use it for fetching data (GET requests) instead&lt;/strong&gt;&lt;/p&gt;


&lt;h2&gt;
  
  
  ⏳ Enabling API Calls Only When Needed
&lt;/h2&gt;

&lt;p&gt;By default, &lt;code&gt;httpResource()&lt;/code&gt; &lt;strong&gt;automatically executes the API call&lt;/strong&gt; whenever the request function changes. However, in some cases, &lt;strong&gt;we don't want the API to trigger immediately&lt;/strong&gt;—for example, when data fetching should only happen &lt;strong&gt;after a user action&lt;/strong&gt; (e.g., clicking a button).&lt;/p&gt;

&lt;p&gt;We can &lt;strong&gt;conditionally enable&lt;/strong&gt; the request by returning undefined when it should not be executed:&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;httpResource&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;@angular/common/http&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="nx"&gt;httpUsers&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;httpResource&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;User&lt;/span&gt;&lt;span class="p"&gt;[]&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;(()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;enabled&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;isApiEnabled&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;enabled&lt;/span&gt; &lt;span class="p"&gt;?&lt;/span&gt; &lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;API_URL&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;/search?q=&lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;query&lt;/span&gt;&lt;span class="p"&gt;()}&lt;/span&gt;&lt;span class="s2"&gt;`&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;undefined&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;&lt;strong&gt;✅ Why is this useful?&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Avoids &lt;strong&gt;unnecessary API calls&lt;/strong&gt; when data isn’t required.&lt;/li&gt;
&lt;li&gt;Helps &lt;strong&gt;control execution flow&lt;/strong&gt;, ensuring the request happens &lt;strong&gt;only&lt;/strong&gt; when a condition is met.&lt;/li&gt;
&lt;li&gt;Ideal for scenarios &lt;strong&gt;like lazy loading, conditional search&lt;/strong&gt;, or &lt;strong&gt;toggle-based requests&lt;/strong&gt;.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;
  
  
  ⚡ What If I Want to Use Pipeable Operators?
&lt;/h2&gt;

&lt;p&gt;Everything is working as expected, but there’s a key difference between rxResource() and httpResource().&lt;/p&gt;

&lt;p&gt;Since &lt;code&gt;httpResource()&lt;/code&gt; does &lt;strong&gt;not expose an observable&lt;/strong&gt;, we &lt;strong&gt;can't apply RxJS operators&lt;/strong&gt; like &lt;code&gt;distinctUntilChanged()&lt;/code&gt; or &lt;code&gt;debounceTime()&lt;/code&gt; directly.&lt;br&gt;
This means we need an &lt;strong&gt;alternative approach&lt;/strong&gt; to manage request optimizations.&lt;/p&gt;

&lt;p&gt;There are &lt;strong&gt;two possible solutions&lt;/strong&gt;:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Use &lt;strong&gt;&lt;code&gt;rxResource()&lt;/code&gt;&lt;/strong&gt; when you need to &lt;strong&gt;transform or process&lt;/strong&gt; the response using RxJS operators.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Create a utility function&lt;/strong&gt; that allows us to &lt;strong&gt;bridge the gap&lt;/strong&gt;, applying RxJS operators to Signals before passing them to &lt;code&gt;httpResource()&lt;/code&gt;.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Let’s explore Approach #2 in detail&lt;/strong&gt;.&lt;/p&gt;
&lt;h2&gt;
  
  
  🔄 From Signal to Observable and Back to Signal
&lt;/h2&gt;

&lt;p&gt;Angular provides &lt;strong&gt;interoperability functions&lt;/strong&gt; that help bridge the gap between &lt;strong&gt;Signals&lt;/strong&gt; and &lt;strong&gt;Observables&lt;/strong&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;toObservable()&lt;/code&gt;&lt;/strong&gt; → Converts a &lt;code&gt;Signal&lt;/code&gt; into an &lt;code&gt;Observable&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;toSignal()&lt;/code&gt;&lt;/strong&gt; → Converts an &lt;code&gt;Observable&lt;/code&gt; back into a &lt;code&gt;Signal&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;By leveraging these utilities, we can &lt;strong&gt;apply RxJS operators&lt;/strong&gt; like &lt;code&gt;debounceTime()&lt;/code&gt; and &lt;code&gt;distinctUntilChanged()&lt;/code&gt; while keeping &lt;code&gt;httpResource()&lt;/code&gt; reactive.&lt;/p&gt;
&lt;h2&gt;
  
  
  🔗 Applying RxJS Operators to Signals
&lt;/h2&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;signal&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;@angular/core&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;httpResource&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;@angular/common/http&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;toObservable&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;toSignal&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;@angular/core/rxjs-interop&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;debounceTime&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;distinctUntilChanged&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;rxjs/operators&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="nx"&gt;inputQuery&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;signal&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="kr"&gt;string&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;''&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="nx"&gt;inputQuery$&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;toObservable&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;inputQuery&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;pipe&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
  &lt;span class="nf"&gt;distinctUntilChanged&lt;/span&gt;&lt;span class="p"&gt;(),&lt;/span&gt; 
  &lt;span class="nf"&gt;debounceTime&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;400&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="nx"&gt;query&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;toSignal&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;inputQuery$&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="nx"&gt;httpUsers&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;httpResource&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;User&lt;/span&gt;&lt;span class="p"&gt;[]&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;(()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;API_URL&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;/search?q=&lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;query&lt;/span&gt;&lt;span class="p"&gt;()}&lt;/span&gt;&lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Here, we use a &lt;strong&gt;Signal&lt;/strong&gt; to manage the input event and trigger API requests while leveraging an &lt;strong&gt;Observable&lt;/strong&gt; to handle the stream flow efficiently.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Note:&lt;br&gt;
This example works as expected, but since we are delaying the event and not the actual API request, the isLoading state could not reflect the truth.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h2&gt;
  
  
  🛠 Simplifying with a Utility Function
&lt;/h2&gt;

&lt;p&gt;To avoid writing this logic repeatedly, we can create a &lt;strong&gt;utility function&lt;/strong&gt; that applies &lt;strong&gt;debouncing and distinct filtering&lt;/strong&gt; to any &lt;code&gt;Signal&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;Signal&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;@angular/core&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;toObservable&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;toSignal&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;@angular/core/rxjs-interop&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;distinctUntilChanged&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;debounceTime&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;rxjs&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;debounceDistinctSignal&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;T&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;signal&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;Signal&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;T&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;time&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;number&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;obs$&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;toObservable&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;signal&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;pipe&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="nf"&gt;distinctUntilChanged&lt;/span&gt;&lt;span class="p"&gt;(),&lt;/span&gt;
    &lt;span class="nf"&gt;debounceTime&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;time&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="p"&gt;);&lt;/span&gt;

  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nf"&gt;toSignal&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;obs$&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Now, we can &lt;strong&gt;simplify our original implementation&lt;/strong&gt; like this:&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;httpResource&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;@angular/common/http&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;debounceDistinctSignal&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;signal-utils&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="nx"&gt;query&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;debounceDistinctSignal&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;inputQuery&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;400&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="nx"&gt;httpUsers&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;httpResource&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;User&lt;/span&gt;&lt;span class="p"&gt;[]&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;(()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;API_URL&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;/search?q=&lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;query&lt;/span&gt;&lt;span class="p"&gt;()}&lt;/span&gt;&lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h2&gt;
  
  
  🎯 Try it in Action! 🚀
&lt;/h2&gt;

&lt;p&gt;Want to see &lt;code&gt;httpResource()&lt;/code&gt; in action? Check out this &lt;strong&gt;interactive StackBlitz demo&lt;/strong&gt;, where you can:&lt;/p&gt;

&lt;p&gt;✅ Experiment with &lt;code&gt;httpResource()&lt;/code&gt; for API calls&lt;br&gt;
✅ Test a &lt;strong&gt;search bar with debounce &amp;amp; distinctUntilChanged&lt;/strong&gt;&lt;br&gt;
✅ Compare side-by-side with &lt;code&gt;rxResource()&lt;/code&gt; and &lt;code&gt;resource()&lt;/code&gt;&lt;/p&gt;


&lt;div class="crayons-card c-embed text-styles text-styles--secondary"&gt;
    &lt;a href="https://stackblitz.com/~/github.com/giorgiogalassi/resource?file=src/app/pages/http-resources.ts" rel="noopener noreferrer"&gt;
      stackblitz.com
    &lt;/a&gt;
&lt;/div&gt;



&lt;h2&gt;
  
  
  📖 Summary &amp;amp; Next Steps
&lt;/h2&gt;

&lt;p&gt;Here’s what we’ve learned in this article:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;code&gt;httpResource()&lt;/code&gt; simplifies API calls&lt;/strong&gt; by integrating directly with &lt;code&gt;HttpClient&lt;/code&gt;.&lt;br&gt;
&lt;strong&gt;&lt;code&gt;toObservable()&lt;/code&gt; and &lt;code&gt;toSignal()&lt;/code&gt; provide interoperability&lt;/strong&gt; between Signals and RxJS.&lt;br&gt;
&lt;strong&gt;A custom utility function (&lt;code&gt;debounceDistinctSignal()&lt;/code&gt;) helps clean up our code&lt;/strong&gt; and makes this approach reusable.&lt;/p&gt;




&lt;p&gt;Thank you for staying with me, and I hope everything was clear. Feel free to explore more of my articles and &lt;strong&gt;&lt;a href="https://www.linkedin.com/in/giorgiogalassi/" rel="noopener noreferrer"&gt;follow me on LinkedIn!&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;See you in the next one!&lt;/p&gt;

&lt;p&gt;Best, G.&lt;/p&gt;

</description>
      <category>typescript</category>
      <category>angular</category>
      <category>httpresource</category>
      <category>http</category>
    </item>
    <item>
      <title>Angular v19+ — Understanding the New resource() and rxResource() APIs 🔥🚀</title>
      <dc:creator>Giorgio Galassi</dc:creator>
      <pubDate>Thu, 20 Mar 2025 10:49:13 +0000</pubDate>
      <link>https://dev.to/ggalassi/angular-v19-understanding-the-new-resource-and-rxresource-apis-3393</link>
      <guid>https://dev.to/ggalassi/angular-v19-understanding-the-new-resource-and-rxresource-apis-3393</guid>
      <description>&lt;p&gt;&lt;strong&gt;Angular 19 is here, and its renaissance continues, further embracing the power of signals.&lt;/strong&gt;&lt;br&gt;
This release introduces two new primitives that simplify handling asynchronous requests: &lt;strong&gt;&lt;code&gt;resource()&lt;/code&gt;&lt;/strong&gt; and &lt;strong&gt;&lt;code&gt;rxResource()&lt;/code&gt;&lt;/strong&gt;. These APIs enable a cleaner and more intuitive way to manage asynchronous data in Angular applications.&lt;/p&gt;

&lt;p&gt;While &lt;code&gt;resource()&lt;/code&gt; and &lt;code&gt;rxResource()&lt;/code&gt; provide powerful tools for handling API calls reactively, &lt;strong&gt;Angular 19.2&lt;/strong&gt; introduces yet another step forward: &lt;strong&gt;&lt;code&gt;httpResource()&lt;/code&gt;&lt;/strong&gt;, a new API that integrates seamlessly with &lt;code&gt;HttpClient&lt;/code&gt;, eliminating even more boilerplate.&lt;br&gt;
If you're interested in taking reactive API calls to the next level, don't miss our deep dive into &lt;strong&gt;&lt;code&gt;httpResource()&lt;/code&gt;&lt;/strong&gt; and how it compares with the existing solutions.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Check out the new article on httpResource() 👇🏻&lt;/strong&gt;&lt;/p&gt;


&lt;div class="ltag__link"&gt;
  &lt;a href="/ggalassi" class="ltag__link__link"&gt;
    &lt;div class="ltag__link__pic"&gt;
      &lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1717803%2F759ae242-5db3-40d9-b13a-80ef26bcf1bc.jpeg" alt="ggalassi"&gt;
    &lt;/div&gt;
  &lt;/a&gt;
  &lt;a href="https://dev.to/ggalassi/angular-v19-understanding-the-new-httpresource-api-23h" class="ltag__link__link"&gt;
    &lt;div class="ltag__link__content"&gt;
      &lt;h2&gt;Angular v19+ — Understanding the New httpResource() API 🔥🚀&lt;/h2&gt;
      &lt;h3&gt;Giorgio Galassi ・ Mar 20&lt;/h3&gt;
      &lt;div class="ltag__link__taglist"&gt;
        &lt;span class="ltag__link__tag"&gt;#typescript&lt;/span&gt;
        &lt;span class="ltag__link__tag"&gt;#angular&lt;/span&gt;
        &lt;span class="ltag__link__tag"&gt;#httpresource&lt;/span&gt;
        &lt;span class="ltag__link__tag"&gt;#http&lt;/span&gt;
      &lt;/div&gt;
    &lt;/div&gt;
  &lt;/a&gt;
&lt;/div&gt;


&lt;blockquote&gt;
&lt;p&gt;Note: These APIs are still in experimental state!&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  Signals: A Quick Refresher
&lt;/h2&gt;

&lt;p&gt;Signals represent a new paradigm for Angular application development. Paired with a &lt;strong&gt;&lt;a href="https://angular.dev/guide/experimental/zoneless" rel="noopener noreferrer"&gt;Zoneless&lt;/a&gt;&lt;/strong&gt; approach, they not only enhance application performance but also improve the Developer Experience (DX).&lt;/p&gt;

&lt;p&gt;By using a signal in your view, you can precisely inform Angular which node in the component tree needs to be updated. This fine-grained reactivity results in faster updates and a more efficient rendering pipeline.&lt;/p&gt;

&lt;p&gt;Here’s a quick example demonstrating how to create and manipulate a signal in Angular:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;Component&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;signal&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;@angular/core&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="p"&gt;@&lt;/span&gt;&lt;span class="nd"&gt;Component&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
  &lt;span class="na"&gt;selector&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;my-component&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;template&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;`
    &amp;lt;p&amp;gt;{{ counter() }}&amp;lt;/p&amp;gt;

    &amp;lt;button (click)="add()"&amp;gt;Add&amp;lt;/button&amp;gt;
    &amp;lt;button (click)="remove()"&amp;gt;Remove&amp;lt;/button&amp;gt;
    &amp;lt;button (click)="reset()"&amp;gt;Reset&amp;lt;/button&amp;gt;
  `&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;})&lt;/span&gt;
&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;MyComponent&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;counter&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;signal&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="kr"&gt;number&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

  &lt;span class="nf"&gt;add&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;counter&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;update&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;current&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;current&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="nf"&gt;remove&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;counter&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;update&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;current&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;current&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="nf"&gt;reset&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;counter&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;set&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h2&gt;
  
  
  Which Problem Are They Solving?
&lt;/h2&gt;

&lt;p&gt;In the early days of Angular signals, several new patterns emerged. One of these patterns tackled how to combine signals with the &lt;code&gt;HttpClient&lt;/code&gt; to manage API responses. A common implementation might look like this:&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;Injectable&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;inject&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;signal&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;@angular/core&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;HttpClient&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;@angular/common/http&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;map&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;rxjs&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;API_URL&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;User&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;./user&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="p"&gt;@&lt;/span&gt;&lt;span class="nd"&gt;Injectable&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="na"&gt;providedIn&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;root&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="p"&gt;})&lt;/span&gt;
&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;ApiService&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="err"&gt;#&lt;/span&gt;&lt;span class="nx"&gt;http&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;inject&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;HttpClient&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="err"&gt;#&lt;/span&gt;&lt;span class="nx"&gt;response&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;signal&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;User&lt;/span&gt;&lt;span class="p"&gt;[]&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="kc"&gt;null&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kc"&gt;null&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

  &lt;span class="kd"&gt;get&lt;/span&gt; &lt;span class="nf"&gt;users&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="err"&gt;#&lt;/span&gt;&lt;span class="nx"&gt;response&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;asReadonly&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="nf"&gt;doApiCall&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;request&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;string&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;''&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="err"&gt;#&lt;/span&gt;&lt;span class="nx"&gt;http&lt;/span&gt;
      &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="kd"&gt;get&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;users&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;User&lt;/span&gt;&lt;span class="p"&gt;[]&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;API_URL&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;/search?q=&lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;request&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
      &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;pipe&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;map&lt;/span&gt;&lt;span class="p"&gt;(({&lt;/span&gt; &lt;span class="nx"&gt;users&lt;/span&gt; &lt;span class="p"&gt;})&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;users&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
      &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;subscribe&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;response&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="err"&gt;#&lt;/span&gt;&lt;span class="nx"&gt;response&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;set&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;response&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;While functional, this approach feels clunky and verbose. It introduces unnecessary boilerplate and requires developers to manually manage loading and error states. Moreover, mixing signals with observables can lead to code that is harder to maintain and reason about, reducing clarity and increasing cognitive overhead.&lt;/p&gt;
&lt;h2&gt;
  
  
  resource(): Simplifying Asynchronous API Calls
&lt;/h2&gt;

&lt;p&gt;The new &lt;a href="https://angular.dev/guide/signals/resource" rel="noopener noreferrer"&gt;&lt;code&gt;resource&lt;/code&gt;&lt;/a&gt; primitive in Angular provides an elegant way to manage asynchronous API calls in a signal-based application. By leveraging &lt;code&gt;resource&lt;/code&gt;, you can seamlessly integrate reactive API calls into your app with better state handling and cleaner code.&lt;/p&gt;

&lt;p&gt;Here’s an example of how &lt;code&gt;resource()&lt;/code&gt; can be used:&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;Component&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;signal&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;resource&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;@angular/core&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="p"&gt;@&lt;/span&gt;&lt;span class="nd"&gt;Component&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
  &lt;span class="na"&gt;selector&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;my-component&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;template&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;`
    &amp;lt;input (input)="search($event)" placeholder="Search user..."/&amp;gt;

    &amp;lt;br /&amp;gt;
    &amp;lt;ul&amp;gt;
      @let error = users.error();
      @if (error) {
        &amp;lt;p&amp;gt;{{ error }}&amp;lt;/p&amp;gt;
      }

      @if (users.isLoading()) {
        &amp;lt;p&amp;gt;Loading Users...&amp;lt;/p&amp;gt;
      }

      @for (user of users.value(); track user.id) {
        &amp;lt;li&amp;gt;{{ user.firstName }} {{ user.lastName }}&amp;lt;/li&amp;gt;
      } @empty {
        &amp;lt;p&amp;gt;No Users!&amp;lt;/p&amp;gt;
      }
    &amp;lt;/ul&amp;gt;
  `&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;})&lt;/span&gt;
&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;MyComponent&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;query&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;signal&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="kr"&gt;string&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;""&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

  &lt;span class="c1"&gt;// The resource can be typed as follows:&lt;/span&gt;
  &lt;span class="c1"&gt;// resource&amp;lt;response type, request type&amp;gt;&lt;/span&gt;
  &lt;span class="nx"&gt;users&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;resource&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;User&lt;/span&gt;&lt;span class="p"&gt;[],&lt;/span&gt; &lt;span class="kr"&gt;string&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
    &lt;span class="na"&gt;request&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;query&lt;/span&gt;&lt;span class="p"&gt;(),&lt;/span&gt;
    &lt;span class="na"&gt;loader&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="k"&gt;async &lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="nx"&gt;request&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;abortSignal&lt;/span&gt; &lt;span class="p"&gt;})&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;response&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nf"&gt;fetch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;API_URL&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;/search?q=&lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;request&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="na"&gt;signal&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;abortSignal&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="p"&gt;});&lt;/span&gt;

      &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="nx"&gt;response&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;ok&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;throw&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Error&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Unable to load users!&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
      &lt;span class="k"&gt;return &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;response&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;json&lt;/span&gt;&lt;span class="p"&gt;()).&lt;/span&gt;&lt;span class="nx"&gt;users&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;},&lt;/span&gt;
  &lt;span class="p"&gt;});&lt;/span&gt;

  &lt;span class="nf"&gt;search&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;event&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;Event&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
     &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;value&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;event&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;target&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="nx"&gt;HTMLInputElement&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
     &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;query&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;set&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;value&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h2&gt;
  
  
  Diving Deeper into the resource() API
&lt;/h2&gt;

&lt;p&gt;The &lt;code&gt;resource()&lt;/code&gt; API introduces two essential components to handle asynchronous data:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;request&lt;/code&gt;&lt;/strong&gt;: A function that returns a value used for the loader computation. Every time &lt;code&gt;query()&lt;/code&gt; changes, the &lt;code&gt;loader&lt;/code&gt; function is re-triggered, behaving similarly to a computed signal.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;loader&lt;/code&gt;&lt;/strong&gt;: The function where the actual API call is performed. It must return a promise, and errors can be handled like any standard promise.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;
  
  
  Built-In Properties of resource()
&lt;/h2&gt;

&lt;p&gt;The resource primitive comes with several useful out-of-the-box properties, all of which are signals:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;value()&lt;/code&gt;&lt;/strong&gt;: Retrieves the current value of the resource's response.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;isLoading()&lt;/code&gt;&lt;/strong&gt;: Indicates whether the resource is currently loading.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;error()&lt;/code&gt;&lt;/strong&gt;: Contains the error, if any, encountered during the API call.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;
  
  
  What About rxResource()?
&lt;/h2&gt;

&lt;p&gt;While &lt;code&gt;resource()&lt;/code&gt; uses a promise-based loader, &lt;code&gt;rxResource()&lt;/code&gt; provides a similar abstraction but leverages Observable streams instead. This makes it a perfect fit for scenarios where your application is already heavily reliant on RxJS or where Observables are the preferred choice for handling asynchronous data.&lt;/p&gt;

&lt;p&gt;To illustrate this, let’s look at an example of how rxResource() can be used to perform a backend call while applying RxJS operators like distinctUntilChanged and map:&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="nx"&gt;rxUsers&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;rxResource&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;User&lt;/span&gt;&lt;span class="p"&gt;[],&lt;/span&gt; &lt;span class="kr"&gt;string&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="kc"&gt;undefined&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
  &lt;span class="na"&gt;request&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;query&lt;/span&gt;&lt;span class="p"&gt;(),&lt;/span&gt;
  &lt;span class="na"&gt;loader&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="nx"&gt;request&lt;/span&gt; &lt;span class="p"&gt;})&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt;
    &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="err"&gt;#&lt;/span&gt;&lt;span class="nx"&gt;http&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="kd"&gt;get&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;users&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;User&lt;/span&gt;&lt;span class="p"&gt;[]&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;API_URL&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;/search?q=&lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;request&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;pipe&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
      &lt;span class="nf"&gt;distinctUntilChanged&lt;/span&gt;&lt;span class="p"&gt;(),&lt;/span&gt;
      &lt;span class="nf"&gt;map&lt;/span&gt;&lt;span class="p"&gt;(({&lt;/span&gt; &lt;span class="nx"&gt;users&lt;/span&gt; &lt;span class="p"&gt;})&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;users&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
      &lt;span class="nf"&gt;catchError&lt;/span&gt;&lt;span class="p"&gt;(()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;throw&lt;/span&gt; &lt;span class="nc"&gt;Error&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Unable to load!&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
      &lt;span class="p"&gt;})&lt;/span&gt;
    &lt;span class="p"&gt;),&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h2&gt;
  
  
  Practical Example and Hands-On Exploration
&lt;/h2&gt;

&lt;p&gt;The power of &lt;code&gt;resource()&lt;/code&gt; and &lt;code&gt;rxResource()&lt;/code&gt; becomes evident when managing complex asynchronous workflows in your Angular application. By combining signals and these primitives, you can reduce boilerplate code while maintaining clarity and reactivity.&lt;/p&gt;

&lt;p&gt;For example:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Dynamically update UI components based on isLoading() or error() states.&lt;/li&gt;
&lt;li&gt;Create powerful search interfaces, as shown in the code above, that adapt in real-time as the user interacts.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;To see these concepts in action, check out this interactive StackBlitz example:&lt;/p&gt;


&lt;div class="crayons-card c-embed text-styles text-styles--secondary"&gt;
    &lt;a href="https://stackblitz.com/~/github.com/giorgiogalassi/resource?file=src/app/pages/resources.ts" rel="noopener noreferrer"&gt;
      stackblitz.com
    &lt;/a&gt;
&lt;/div&gt;



&lt;p&gt;In this demo, you’ll find:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;A fully functional search bar integrated with the resource() API.&lt;/li&gt;
&lt;li&gt;Examples of handling loading states, error handling, and real-time updates using signals.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Feel free to experiment by tweaking the code and observing how Angular’s reactivity makes the process seamless.&lt;/p&gt;




&lt;p&gt;Thank you for staying with me, and I hope everything was clear. Feel free to explore more of my articles and &lt;a href="https://www.linkedin.com/in/giorgiogalassi" rel="noopener noreferrer"&gt;&lt;strong&gt;follow me on LinkedIn!&lt;/strong&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;See you in the next one!&lt;/p&gt;

&lt;p&gt;Best, G.&lt;/p&gt;

</description>
      <category>typescript</category>
      <category>angular</category>
      <category>resource</category>
      <category>http</category>
    </item>
  </channel>
</rss>
