<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Anton Marinenko on Medium]]></title>
        <description><![CDATA[Stories by Anton Marinenko on Medium]]></description>
        <link>https://medium.com/@toha.marko?source=rss-1d7d68a9fdf3------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*v616yyVXfkKOJ_wGsIj5Pw.png</url>
            <title>Stories by Anton Marinenko on Medium</title>
            <link>https://medium.com/@toha.marko?source=rss-1d7d68a9fdf3------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Thu, 03 Dec 2026 14:58:25 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@toha.marko/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Keeping Angular Tabs in Sync with BroadcastChannel and Signals]]></title>
            <link>https://levelup.gitconnected.com/keeping-angular-tabs-in-sync-with-broadcastchannel-and-signals-0b516c469e9a?source=rss-1d7d68a9fdf3------2</link>
            <guid isPermaLink="false">https://medium.com/p/0b516c469e9a</guid>
            <category><![CDATA[typescript]]></category>
            <category><![CDATA[angular-signals]]></category>
            <category><![CDATA[broadcast-channel-api]]></category>
            <category><![CDATA[angular]]></category>
            <category><![CDATA[angularjs]]></category>
            <dc:creator><![CDATA[Anton Marinenko]]></dc:creator>
            <pubDate>Thu, 29 Oct 2026 15:40:09 GMT</pubDate>
            <atom:updated>2026-10-29T15:40:09.595Z</atom:updated>
            <content:encoded><![CDATA[<h4>A small example with a shared preference, persistent state, and no message loops.</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*S6Pjgt3FVyR7Tr7jM9RleA.jpeg" /></figure><p>Let’s say our application has a menu with a “Show only pinned items” setting. We open the application in two tabs, change the setting in one, and expect the other to follow.</p><p>Inside each tab, an Angular service can hold the setting in a signal. But each tab runs its own application and has its own service instance. Changing one signal does not update the other.</p><p>Let’s connect them with BroadcastChannel and keep the example small: one setting, one service, and one checkbox.</p><p>The code below targets an existing Angular application with client rendering. It assumes a browser with working BroadcastChannel and localStorage access. Applications with server rendering need a browser-only boundary around this service.</p><h3>What should each part do?</h3><p>We will use localStorage to keep the current preference, BroadcastChannel to tell other tabs that it changed, and a signal to expose the value to Angular templates.</p><p>The message will contain only the kind of change. When another tab receives it, that tab reads the current value from storage.</p><p>Why read it again? A message may be handled after another write has already happened. Reading storage avoids replacing the current preference with an older value carried by a delayed notification.</p><p><a href="https://developer.mozilla.org/en-US/docs/Web/API/BroadcastChannel">BroadcastChannel</a> connects listeners using the same channel name. The sending channel object does not receive its own message, so we must update the originating tab ourselves. This example uses ordinary same-origin tabs in the same browser profile; embedded pages can have additional <a href="https://developer.mozilla.org/en-US/docs/Web/API/Broadcast_Channel_API">storage-partition restrictions</a>.</p><h3>Create the service</h3><p>Put the service in src/app/menu-preferences.service.ts:</p><pre>import { DestroyRef, Injectable, inject, signal } from &#39;@angular/core&#39;;<br><br>const STORAGE_KEY = &#39;demo:menu:pinned-only&#39;;<br>const CHANNEL_NAME = &#39;demo:menu-preferences:v1&#39;;<br>type PreferenceChanged = {<br>  type: &#39;pinned-only-changed&#39;;<br>};<br><br>function isPreferenceChanged(value: unknown): value is PreferenceChanged {<br>  return (<br>    typeof value === &#39;object&#39; &amp;&amp;<br>    value !== null &amp;&amp;<br>    &#39;type&#39; in value &amp;&amp;<br>    value.type === &#39;pinned-only-changed&#39;<br>  );<br>}<br><br>@Injectable({ providedIn: &#39;root&#39; })<br>export class MenuPreferencesService {<br>  private readonly channel = new BroadcastChannel(CHANNEL_NAME);<br>  private readonly destroyRef = inject(DestroyRef);<br>  private readonly pinnedOnlyState = signal(this.readPinnedOnly());<br>  readonly pinnedOnly = this.pinnedOnlyState.asReadonly();<br><br>  constructor() {<br>    this.channel.onmessage = ({ data }: MessageEvent&lt;unknown&gt;) =&gt; {<br>      if (isPreferenceChanged(data)) {<br>        this.refresh();<br>      }<br>    };<br>    this.destroyRef.onDestroy(() =&gt; this.channel.close());<br>  }<br><br>  setPinnedOnly(value: boolean): void {<br>    localStorage.setItem(STORAGE_KEY, String(value));<br>    this.refresh();<br>    this.channel.postMessage({<br>      type: &#39;pinned-only-changed&#39;,<br>    } satisfies PreferenceChanged);<br>  }<br><br>  private refresh(): void {<br>    this.pinnedOnlyState.set(this.readPinnedOnly());<br>  }<br><br>  private readPinnedOnly(): boolean {<br>    return localStorage.getItem(STORAGE_KEY) === &#39;true&#39;;<br>  }<br>}</pre><p>There are two paths through this service.</p><p>A local change calls setPinnedOnly(): it saves the preference, refreshes the local signal, and sends a notification. An incoming notification calls refresh(): it only reads storage and updates the signal.</p><p>That difference prevents a loop. Receiving a message never sends another message, and it never writes an old value back to storage. Keep postMessage() on the local-change path. An effect that broadcasts every signal update would also broadcast changes received from other tabs.</p><p>The writable signal is private. Components get a read-only view and use setPinnedOnly() to change the setting, so they cannot accidentally skip persistence or notification.</p><p><a href="https://v19.angular.dev/api/core/DestroyRef">DestroyRef</a> closes the channel when the service’s injector is destroyed. Since this service uses providedIn: &#39;root&#39;, its lifetime is tied to the application, not to one checkbox component.</p><h3>Connect a component</h3><p>Use this standalone component in src/app/app.component.ts:</p><pre>import { ChangeDetectionStrategy, Component, inject } from &#39;@angular/core&#39;;<br>import { MenuPreferencesService } from &#39;./menu-preferences.service&#39;;<br>@Component({<br>  selector: &#39;app-root&#39;,<br>  standalone: true,<br>  changeDetection: ChangeDetectionStrategy.OnPush,<br>  template: `<br>    &lt;label&gt;<br>      &lt;input<br>        #checkbox<br>        type=&quot;checkbox&quot;<br>        [checked]=&quot;preferences.pinnedOnly()&quot;<br>        (change)=&quot;preferences.setPinnedOnly(checkbox.checked)&quot;<br>      /&gt;<br>      Show only pinned items<br>    &lt;/label&gt;<br>    &lt;p&gt;<br>      Current preference:<br>      {{ preferences.pinnedOnly() ? &#39;Pinned items only&#39; : &#39;All items&#39; }}<br>    &lt;/p&gt;<br>  `,<br>})<br>export class AppComponent {<br>  protected readonly preferences = inject(MenuPreferencesService);<br>}</pre><p>Bootstrap it as the root of a client-rendered Angular application. A minimal src/main.ts is:</p><pre>import { bootstrapApplication } from &#39;@angular/platform-browser&#39;;<br>import { AppComponent } from &#39;./app/app.component&#39;;<br>bootstrapApplication(AppComponent).catch(console.error);</pre><p>The template reads the signal directly. Angular <a href="https://v19.angular.dev/guide/signals#reading-signals-in-onpush-components">tracks signal reads</a> in templates, so changing the signal marks this OnPush component for an update.</p><p>The message handler runs outside the Angular zone: Zone.js does not patch the onmessage property of BroadcastChannel. That is fine. Since Angular 18, a signal update schedules change detection on its own, so the same code works with the default Zone.js setup and with zoneless change detection.</p><p>The component does not need to know whether the change came from its own checkbox or another tab.</p><h3>Try it with two tabs</h3><p>Open the running application at the same URL in two tabs. Check the box in the first tab: the second tab should update too. Uncheck it in the second tab and watch the first one follow.</p><p>Now open a third tab or reload one of the existing tabs. The preference is restored from localStorage. BroadcastChannel does not replay earlier messages; storage supplies the initial value. This initialization also works when none of the earlier tabs are still open.</p><h3>A few boundaries</h3><p>For this single stored boolean, the browser’s <a href="https://developer.mozilla.org/en-US/docs/Web/API/Window/storage_event">storage event</a> is also a reasonable choice. BroadcastChannel is useful when you want explicit application messages, such as a preference change or a request to refresh data. You do not need both notification mechanisms for this example.</p><p>All writes to this preference should go through the service. A direct localStorage.setItem() elsewhere will not send our channel notification.</p><p>If two tabs write at nearly the same time, they read whichever value is currently stored when they refresh. This example does not merge edits or coordinate transactions. The channel provides live notifications without acknowledgements or a durable message queue. It also does not synchronize different devices. A shared document or a server-owned setting needs its own conflict and persistence rules.</p><p>Finally, the signal represents the current preference. If every individual event matters, process those events directly or use an event stream. A signal holding the latest message is not an event history, and <a href="https://angular.dev/ecosystem/rxjs-interop#timing-of-toobservable">toObservable can combine several signal updates into one emission</a>.</p><p>With these boundaries, the same pattern works for small browser-local preferences such as compact mode or a selected display option. Keep the write path explicit, let incoming messages refresh state, and let Angular render the signal.</p><p>Thanks for reading.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=0b516c469e9a" width="1" height="1" alt=""><hr><p><a href="https://levelup.gitconnected.com/keeping-angular-tabs-in-sync-with-broadcastchannel-and-signals-0b516c469e9a">Keeping Angular Tabs in Sync with BroadcastChannel and Signals</a> was originally published in <a href="https://levelup.gitconnected.com/">Level Up Coding</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Angular 19 new resource API: the major point for getting into signals]]></title>
            <link>https://levelup.gitconnected.com/angular-19-new-resource-api-the-major-point-for-getting-into-signals-3b42fa60b982?source=rss-1d7d68a9fdf3------2</link>
            <guid isPermaLink="false">https://medium.com/p/3b42fa60b982</guid>
            <category><![CDATA[angular]]></category>
            <category><![CDATA[typescript]]></category>
            <category><![CDATA[angular-19]]></category>
            <category><![CDATA[frontend]]></category>
            <category><![CDATA[angular-19-resource]]></category>
            <dc:creator><![CDATA[Anton Marinenko]]></dc:creator>
            <pubDate>Wed, 20 Nov 2024 17:14:53 GMT</pubDate>
            <atom:updated>2024-11-21T22:10:12.521Z</atom:updated>
            <content:encoded><![CDATA[<h4>Angular Core</h4><h4>Introduction to Angular 19 resource and rxResource APIs</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*yFusNVPhsmvLNO3wo0ut2A.jpeg" /></figure><p>Angular 19 introduces two <em>experimental</em> APIs, resource and rxResource, aimed at simplifying asynchronous data retrieval and management. These APIs enhance the developer experience by providing a more declarative approach to handling HTTP requests and managing their states.</p><p>There are many times when you need to retrieve data based on dynamic conditions, or when you create a custom loader to indicate that a process is in progress. Additionally, with the signals API, you cannot simply reassign data to computed signals if it depends on a request or another signal. Fortunately, all of these challenges have been addressed with the resource API now.</p><p>Let’s check on practice how does it work.</p><h3>Before</h3><p>Usually, to fetch data, we have to use an Observable with an AsyncPipe to get the value in a template:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/577c52d09ee8eea5045da1cbd2e58b9a/href">https://medium.com/media/577c52d09ee8eea5045da1cbd2e58b9a/href</a></iframe><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e0b543e3236113529319a25c92cee5db/href">https://medium.com/media/e0b543e3236113529319a25c92cee5db/href</a></iframe><p>We have to import the AsyncPipe class explicitly to the current component, and we have to deal with the async Observable data here.</p><h3>Since Angular 17</h3><p>Next, starting from <strong>Angular</strong> version <strong>17</strong>, when the Signals API became stable, we have a more robust way to get values in a template:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f417cd5efdf488c4a3e5bb03a21da5f2/href">https://medium.com/media/f417cd5efdf488c4a3e5bb03a21da5f2/href</a></iframe><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4c547863537583b0f3f67cc995c92391/href">https://medium.com/media/4c547863537583b0f3f67cc995c92391/href</a></iframe><p>From that point, our life becomes easier. No more additional class imports into the current component, and we can access the data signal synchronously.</p><h3>Angular 19</h3><p>Now, we finally have the new API to work with typical data resources — resource API.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4432cd54ca1c9ce557867390de31ff32/href">https://medium.com/media/4432cd54ca1c9ce557867390de31ff32/href</a></iframe><p>Let’s start with the most familiar approach for <strong>Angular</strong> developers to get data from an observable source. For that, we now have the rxResource API. It accepts object with properties as an argument. The loader property should be a function that returns an Observable value. That’s enough to get it work.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/de342e2a663a807f482e6569686fc68e/href">https://medium.com/media/de342e2a663a807f482e6569686fc68e/href</a></iframe><p>The todo property stores data with a ResourceRef type. There is a value property with a signal type value that can be accessed at any time. But let’s dive into other properties in that data:</p><ul><li>hasValue signal data that shows if a value has been set</li><li>isLoading signal data that indicates if data is currently loading or reloading</li><li>status signal data shows the current status</li><li>error signal data that indicates if any errors have occurred</li></ul><p>Additionally, there are few methods to deal with:</p><ul><li>set allows you to set a value for the current data</li><li>update allows you to update the value in a functional approach</li><li>reload allows you to start the loader function explicitly again</li></ul><p>These are all functional tools for creating easy-to-use solutions. For example:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/96790783a65f6edbce1295ed717a6d0b/href">https://medium.com/media/96790783a65f6edbce1295ed717a6d0b/href</a></iframe><p>One of the core points to deal with resource is that you can change the value at any time.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/261c006b50ee8ebb8a1505bbe5279d1f/href">https://medium.com/media/261c006b50ee8ebb8a1505bbe5279d1f/href</a></iframe><p><strong>Resource </strong><strong>request property</strong></p><p>Let’s add more reactivity to receive a data. We can do it by using dependency from the resource API. For example, we need a search:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/85e658513f08e068f44877179cbcf037/href">https://medium.com/media/85e658513f08e068f44877179cbcf037/href</a></iframe><p>We need to pass a request property in the argument to the resource. It accepts a function that executes in a computed context. This means it’s reasonable to pass a signal typed value in the return of the function. Let’s pass value changes of the search control to the request.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/30b236294a42a9534e1fd9f7beec6c61/href">https://medium.com/media/30b236294a42a9534e1fd9f7beec6c61/href</a></iframe><p>Now, with any change in the input element, we will get the corresponding data as a result of re-executed loader function.</p><h4>Resource API</h4><p>The example above describes the rxResource API, which works with an Observable. In fact, it’s a wrapper for the resource API.</p><p>The resource loader works with a <em>Promise </em>return type, and, for example, we can use the Fetch API for that as a common case.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/30b236294a42a9534e1fd9f7beec6c61/href">https://medium.com/media/30b236294a42a9534e1fd9f7beec6c61/href</a></iframe><p>Additionally, if we want to abort a fetch request when the the resource request has changed, there is also an abortSignal property to pass. We can use it this way:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/6a0bda13a79b3ac50152abef2d13a1f4/href">https://medium.com/media/6a0bda13a79b3ac50152abef2d13a1f4/href</a></iframe><p>That is all for now. Thank you for reading.</p><p>Thank you, <a href="https://medium.com/u/b9c466d8885d">Angular</a> team, for your great work 🌟!</p><p>Thank you <a href="https://medium.com/u/a7db01a91fcb">Minko Gechev</a> 🌟!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3b42fa60b982" width="1" height="1" alt=""><hr><p><a href="https://levelup.gitconnected.com/angular-19-new-resource-api-the-major-point-for-getting-into-signals-3b42fa60b982">Angular 19 new resource API: the major point for getting into signals</a> was originally published in <a href="https://levelup.gitconnected.com/">Level Up Coding</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Angular: EventEmitter vs Subject for component output events.]]></title>
            <link>https://blog.stackademic.com/angular-eventemitter-vs-subject-for-component-output-events-ac1ac66b58c7?source=rss-1d7d68a9fdf3------2</link>
            <guid isPermaLink="false">https://medium.com/p/ac1ac66b58c7</guid>
            <category><![CDATA[angular]]></category>
            <category><![CDATA[typescript]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[angularjs]]></category>
            <category><![CDATA[events]]></category>
            <dc:creator><![CDATA[Anton Marinenko]]></dc:creator>
            <pubDate>Wed, 16 Aug 2023 14:12:18 GMT</pubDate>
            <atom:updated>2023-08-17T14:22:55.133Z</atom:updated>
            <content:encoded><![CDATA[<h4>The difference and working example.</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2QzJBjUzYa4Q6Q7wrYgl2A.jpeg" /></figure><p>I frequently encounter individuals who use the @Output decorator within a component with a Subject class as an event emitter. There are numerous discussions regarding the distinction between using a Subject and an EventEmitter. While some argue that there is no difference, let&#39;s explore the facts to gain a better understanding.</p><p>EventEmitter source:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/972e8c850581d7d0d9d6eddc748395e2/href">https://medium.com/media/972e8c850581d7d0d9d6eddc748395e2/href</a></iframe><p>So, now we can infer the key concepts about EventEmitter :</p><ol><li>EventEmitter extends Subject, — this means we can use <em>Liskov substitution principle</em> in practice (🙌 SOLID).</li><li>EventEmitter has an additional property in the constructor named isAsync. In fact that’s the main difference between this class and Subject.</li><li>EventEmitter can emit asynchronous events if isAsync is true.</li></ol><p>That’s all the difference. However, when it comes to Angular, it’s generally recommended to use EventEmitters semantically, where they are supposed to be used. This helps maintain a clean and organized codebase, making it easier to understand and maintain the application over time.</p><p>Here is an example app to choose the fruit:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/2b5dfdbcf19f378fc46645585654e803/href">https://medium.com/media/2b5dfdbcf19f378fc46645585654e803/href</a></iframe><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/cb23fcd629889d5f58d55370e272582c/href">https://medium.com/media/cb23fcd629889d5f58d55370e272582c/href</a></iframe><p>There are simple operations here. You can choose between two components to pick a fruit.</p><p>Typical fruit component:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d4fcee4769b9a5935661ee05a0ed1ad6/href">https://medium.com/media/d4fcee4769b9a5935661ee05a0ed1ad6/href</a></iframe><p>And the logic is here: when you click on the component, the click event listener inside the fruit component is triggered first, which emits the “fruit” value to the parent component. Then, the parent component receives the emission and updates its state accordingly, after which it displays the “Goodbye” message. The concurrency of click events is handled by JavaScript through the propagation principle, ensuring that the fruit component’s state is updated before the parent component displays the “Goodbye” message. If this were done synchronously, the fruit would be changed before the “Goodbye” message was displayed.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*MC--AAl7pCXDmJd8eiZWmw.png" /><figcaption>Synchronous EventEmitter event</figcaption></figure><p>If this were done asynchronously, the fruit would be changed after the “Goodbye” message was displayed. Actually this is what we need.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*dWhoGKlr3o9v4T65GkToLA.png" /><figcaption>Asynchronous EventEmitter event</figcaption></figure><p>That’s it! Feel free to experiment with this example on <a href="https://stackblitz.com/edit/stackblitz-starters-k288te?file=src%2Fmain.ts">Stackblitz</a>.</p><p><em>Thank you for reading until the end. Please consider following the writer and this publication. Visit </em><a href="https://stackademic.com/"><em>Stackademic</em></a><em> to find out more about how we are democratizing free programming education around the world.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ac1ac66b58c7" width="1" height="1" alt=""><hr><p><a href="https://blog.stackademic.com/angular-eventemitter-vs-subject-for-component-output-events-ac1ac66b58c7">Angular: EventEmitter vs Subject for component output events.</a> was originally published in <a href="https://blog.stackademic.com/">Stackademic</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Angular 16: Contemporary way to push data to a route component]]></title>
            <link>https://levelup.gitconnected.com/angular-16-contemporary-way-to-push-data-to-a-route-component-c0e6ebda0f26?source=rss-1d7d68a9fdf3------2</link>
            <guid isPermaLink="false">https://medium.com/p/c0e6ebda0f26</guid>
            <category><![CDATA[angular2]]></category>
            <category><![CDATA[angular]]></category>
            <category><![CDATA[routing]]></category>
            <category><![CDATA[angularjs]]></category>
            <category><![CDATA[typescript]]></category>
            <dc:creator><![CDATA[Anton Marinenko]]></dc:creator>
            <pubDate>Sun, 11 Jun 2023 15:53:49 GMT</pubDate>
            <atom:updated>2023-06-13T03:59:08.880Z</atom:updated>
            <content:encoded><![CDATA[<h4>New feature in Angular 16 for routing</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*dpn4Xm67EIcPS3eXt1NVjg.jpeg" /></figure><p>Angular is growing rapidly this days, providing user-friendly and simple way to develop an application. In this article I would like to focus your attention on the use of route components, which is a new feature not so long ago. More specifically, we will explore a new approach to pass data into route components using Input() decorated properties.</p><h4>For start</h4><p>We need to enable ability to pass data.</p><p>Angular documentation says:</p><blockquote>Use a route to pass this type of information to your application components. To do so, you use the <a href="https://angular.io/api/router/withComponentInputBinding">withComponentInputBinding</a> feature with <a href="https://angular.io/api/router/provideRouter">provideRouter</a> or the bindToComponentInputs option of RouterModule.forRoot.</blockquote><p>This means you can do this setup:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/27332815af8c25734a9eba590fa62b7d/href">https://medium.com/media/27332815af8c25734a9eba590fa62b7d/href</a></iframe><p>or this:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1f55f0b6bcf70df5d81563cc60cb8781/href">https://medium.com/media/1f55f0b6bcf70df5d81563cc60cb8781/href</a></iframe><h4>What this article about</h4><p>Let’s see what we can pass to the Input() :</p><blockquote>You can bind all route data with key, value pairs to component inputs: static or resolved route data, path parameters, matrix parameters, and query parameters.</blockquote><p>The most intriguing aspect is how all of these parameters would work together and who would win the race?</p><p>Let’s create a simple example:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/21006b1f6bd8b059c9ae1206c475a05d/href">https://medium.com/media/21006b1f6bd8b059c9ae1206c475a05d/href</a></iframe><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/25d4cee3c4583303385374a20dc67871/href">https://medium.com/media/25d4cee3c4583303385374a20dc67871/href</a></iframe><ol><li>Passing <em>query parameters.</em> By the addition of url ?input=queryValue everything works fine and the input property in the Child component now stores value “<em>queryValue</em>”. It even works well if we change this parameter over time with navigation.</li></ol><p>Next, let’s add a path parameter there:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a1e12ece6fd8b30b39ab5e602e271688/href">https://medium.com/media/a1e12ece6fd8b30b39ab5e602e271688/href</a></iframe><p>2. Passing <em>path parameter.</em> By the addition of url /pathParam?input=queryValue we get the input property in the Child component that stores value “<em>pathParam</em>”. This means the query params are ignored.</p><p>3. Passing <em>matrix parameters.</em> By addition of url /pathParam;input=matrixParam?input=queryValue we get the input property in the Child component that stores value “<em>matrixParam</em>”. This means all other params are ignored.</p><p>Finally, let’s add data to the route:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c9a9403d2584abc09e43e8a208a2521b/href">https://medium.com/media/c9a9403d2584abc09e43e8a208a2521b/href</a></iframe><p>4. Passing <em>route data.</em> By passing the route data we get the input property in the Child component that stores value “<em>dataParam</em>”, even all other params are passed as well. This means that all other params have been ignored.</p><h4>Result</h4><p>To enable routing input bindings feature you need to activate flag within routing settings.</p><p>An Input parameter in a route component is set only once per navigation with the highest-priority parameter value passed in.</p><p>Priority rates (low to high):</p><ol><li>Query Parameters</li><li>Path Parameters</li><li>Matrix Parameters</li><li>Route Data</li></ol><h3>Level Up Coding</h3><p>Thanks for being a part of our community! Before you go:</p><ul><li>👏 Clap for the story and follow the author 👉</li><li>📰 View more content in the <a href="https://levelup.gitconnected.com/?utm_source=pub&amp;utm_medium=post">Level Up Coding publication</a></li><li>💰 Free coding interview course ⇒ <a href="https://skilled.dev/?utm_source=luc&amp;utm_medium=article">View Course</a></li><li>🔔 Follow us: <a href="https://twitter.com/gitconnected">Twitter</a> | <a href="https://www.linkedin.com/company/gitconnected">LinkedIn</a> | <a href="https://newsletter.levelup.dev/">Newsletter</a></li></ul><p>🚀👉 <a href="https://jobs.levelup.dev/talent/welcome?referral=true"><strong>Join the Level Up talent collective and find an amazing job</strong></a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c0e6ebda0f26" width="1" height="1" alt=""><hr><p><a href="https://levelup.gitconnected.com/angular-16-contemporary-way-to-push-data-to-a-route-component-c0e6ebda0f26">Angular 16: Contemporary way to push data to a route component</a> was originally published in <a href="https://levelup.gitconnected.com/">Level Up Coding</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Angular: A new Component approach for creating an App]]></title>
            <link>https://levelup.gitconnected.com/angular-a-new-component-approach-for-creating-an-app-1d0fef43d77?source=rss-1d7d68a9fdf3------2</link>
            <guid isPermaLink="false">https://medium.com/p/1d0fef43d77</guid>
            <category><![CDATA[routing]]></category>
            <category><![CDATA[angular]]></category>
            <category><![CDATA[standalone-component]]></category>
            <category><![CDATA[typescript]]></category>
            <category><![CDATA[angularjs]]></category>
            <dc:creator><![CDATA[Anton Marinenko]]></dc:creator>
            <pubDate>Sun, 19 Feb 2023 14:17:26 GMT</pubDate>
            <atom:updated>2023-03-01T01:48:49.572Z</atom:updated>
            <content:encoded><![CDATA[<h4>Angular Common</h4><h4>It’s good without modules, isn’t it?</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*PwmFkimyCg-bU1NIhXsvhw.jpeg" /></figure><h4>Introduction</h4><p><em>Angular</em> is a popular JavaScript framework used for developing web applications. It provides developers with a robust set of tools to build complex, scalable, and performant applications. One of the key features of <em>Angular</em> is its component-based architecture, which allows developers to break down the application into smaller, reusable pieces.</p><p>With the release of version 14,<em> Angular</em> introduced the concept of standalone components, updating the traditional approach to application design. And now, in version 15, standalone components are ready for use in production builds.</p><p>Actually, the role of modules is now becoming to components. No need for creating separate module and declare components here. We can do everything without the standalone component.</p><p>In my view, modules provide a clear and explicit way to define an application architecture. However, this approach can sometimes result in a loss of flexibility. On the other hand, standalone components can be more flexible, but they may require a larger @Component decorator due to the need to import and provide dependencies that would otherwise be defined within a module.</p><h4><strong>Code</strong></h4><p>Let’s create an application with a new standalone approach and check the key points:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/0a1b6f2275aab1bcb8c73ac9fc5cff57/href">https://medium.com/media/0a1b6f2275aab1bcb8c73ac9fc5cff57/href</a></iframe><p>This is actually all the script we need to run the <em>Angular</em> app in the browser and it works! Now this is a much cleaner solution with less code.</p><p>So, now we need a routing. We have to declare providers at the root level, because we don’t have an App module.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/6055714348b0ce1537aacb20daa016dc/href">https://medium.com/media/6055714348b0ce1537aacb20daa016dc/href</a></iframe><p>We can now use the new loadComponent method in routing to lazy load components.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/fb59f92b65db02b53c5bbe8412fe6fa0/href">https://medium.com/media/fb59f92b65db02b53c5bbe8412fe6fa0/href</a></iframe><p><strong>That’s it.</strong></p><p>Now our application runs on <em>Angular</em> with the routing. Also if you need to load children routes just use the loadChildren method and pass routes there.</p><p>As you can agree, the code has become much smaller compared to the modular approach. Of course, we would like to get rid of the imports property as well, but maybe this will be achievable in the future.</p><h4>One more</h4><p>I would like to address another aspect of working with routing. Often, when using reusable components, there is a need to use <em>DI</em> to denote the context. In the current approach, we can only designate the provider for the component, and this solution won’t work. However, <em>Angular</em> has recently introduced a new feature that allows adding providers in routing. Let’s make use of it!</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f1aadd1793ec9f0af238677edfbc7cd4/href">https://medium.com/media/f1aadd1793ec9f0af238677edfbc7cd4/href</a></iframe><p>Thanks for your attention.</p><blockquote>May Angular be with you.</blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1d0fef43d77" width="1" height="1" alt=""><hr><p><a href="https://levelup.gitconnected.com/angular-a-new-component-approach-for-creating-an-app-1d0fef43d77">Angular: A new Component approach for creating an App</a> was originally published in <a href="https://levelup.gitconnected.com/">Level Up Coding</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Angular: DI, Services, and Injectors]]></title>
            <link>https://medium.com/better-programming/angular-di-services-and-injectors-1f777e883e18?source=rss-1d7d68a9fdf3------2</link>
            <guid isPermaLink="false">https://medium.com/p/1f777e883e18</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[front-end-development]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[angular]]></category>
            <category><![CDATA[typescript]]></category>
            <dc:creator><![CDATA[Anton Marinenko]]></dc:creator>
            <pubDate>Mon, 30 May 2022 07:08:42 GMT</pubDate>
            <atom:updated>2022-05-31T04:40:42.223Z</atom:updated>
            <content:encoded><![CDATA[<h4>How dependency injection works with services</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ZNrfKOZi7qB6ZjDK5QYy0A.jpeg" /></figure><p>Let’s talk about the Dependency Injection system in Angular, discuss a little about injectors, and decide on ways to implement service providers.</p><p>The Angular documentation describes the system of injectors quite well, but for a complete understanding, it is worth paying a little more detailed attention to this.</p><p>Additionally, it should be noted how services are loaded: immediately upon loading the application or as they are used?</p><p>Let’s look at the scheme of building <em>DI</em> in Angular. There are several levels of injectors, and each new module/component/directive has its own level of injectors. In <em>version</em> <em>14</em> of Angular, a new level of injection was added in routes.</p><p>The system is similar to a tree structure, and if you represent it graphically, you get the following view:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*LfOv1onNbWCTq2MjTrcrlQ.png" /></figure><p>The search for injectors goes from children to parents and so on until NullInjector.</p><p>If there is no entry in <em>Dependency Injection</em> about the injected service, then you can get a fairly common error:</p><pre>NullInjectorError: No provider for YourService!</pre><p>As you can suppose, this error can be fixed by declaring the service in the application or in the required module.</p><p>Angular documentation recommends using singleton services, which is often the right approach, and providing them in root. Like this:</p><pre>@Injectable({ providedIn: &#39;root&#39; })</pre><p>What does this mean, where does the &#39;root&#39; come from? When the application starts, this &#39;root&#39; level of injectors is created, and it is determined by the context that we load in the bootstrapModule method. This module or component(starting from <em>version 14</em> this is possible with <em>standalone</em>) will be the &#39;root&#39; level of the tree. In addition, as you can see in the scheme above, there are also parents &#39;platform&#39; and NullInjector <em>DI</em> levels.</p><p>Thus, by declaring providedIn: &#39;root&#39;, we thereby indicate to the <em>DI</em> system that the reference to the current instance of the service is located at the &#39;root&#39;. This is important to understand, this is how a <em>Dependency Injection</em> tree is combined.</p><p>Now let’s look at the possible options for declaring a service.</p><p>The first variant is declare inside the @Injectable decorator of the service itself with property:</p><pre>providedIn?: Type&lt;any&gt; | ‘root’ | ‘platform’ | ‘any’ | null;</pre><p>The Angular documentation details the effect of the providedIn property arguments:</p><ul><li>Type&lt;any&gt;: Associates the injectable with an @NgModule or other InjectorType. We can declare a module where service will be instanciated and injected to DI, example: @Injectable({ providedIn: YourModule }).</li><li>null (here the equivalent to undefined): The injectable is not provided in any scope automatically. We have to add the service to providers list additionally within Providers property.</li></ul><p>InjectorType:</p><ul><li>&#39;root&#39;: The application-level injector in most apps.</li><li>&#39;platform&#39;: A special singleton platform injector shared by all applications on the page.</li><li>&#39;any&#39;: Provides a unique instance in each lazy loaded module while all eagerly loaded modules share one instance.</li></ul><p>The second variant is the service declaration follows from the first variant with the empty property providedIn: @Injectable(), wich is undefined and similar to this:</p><pre>@Injectable({ providedIn: null })</pre><p>Next, you need to declare a service in the Providers property in the directive/component/module and an instance of this service will be created at this <em>DI</em> level.</p><p>There should be noted that even if the service was created as in the first variant described, declaring this service in Providers will lead to the creation of a new instance of this service and a reference to it in DI tree. Thus, a situation is possible when in the <em>DI</em> tree at different levels there will be different instances of the same service.</p><p>Additionally, in Angular <em>version 14</em>, you can use an extra DI level with property Providers in Routes.</p><p>There is an example view:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*51QEFguuVIkaTMwIA5svfQ.png" /></figure><p>And now about loading @Injectable() classes code, — they are downloaded on the client regardless of the declaration method, but with the first module class chunk using the injectable class directly (at least with the declaration in the constructor).</p><p>Thanks, that’s all about @Injectable() for today.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1f777e883e18" width="1" height="1" alt=""><hr><p><a href="https://medium.com/better-programming/angular-di-services-and-injectors-1f777e883e18">Angular: DI, Services, and Injectors</a> was originally published in <a href="https://betterprogramming.pub/">Better Programming</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[When to Use Angular ControlValueAccessor and What’s the Difference Without It?]]></title>
            <link>https://medium.com/better-programming/angular-with-controlvalueaccessor-and-without-less-boilerplate-da27f0a16639?source=rss-1d7d68a9fdf3------2</link>
            <guid isPermaLink="false">https://medium.com/p/da27f0a16639</guid>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[typescript]]></category>
            <category><![CDATA[front-end-development]]></category>
            <category><![CDATA[angular]]></category>
            <dc:creator><![CDATA[Anton Marinenko]]></dc:creator>
            <pubDate>Mon, 02 May 2022 14:49:56 GMT</pubDate>
            <atom:updated>2022-05-04T00:31:24.467Z</atom:updated>
            <content:encoded><![CDATA[<h4>Angular Forms</h4><h4>Angular with ControlValueAccessor and without — less boilerplate.</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*L39XMxf0AI_Jq5b7gsSqFQ.jpeg" /></figure><p>Today let’s do some research about ControlValueAccessor usage, when we should use it and when it’s redundant.</p><p>ControlValueAccessor provides the ability to use FormControl with any component that implements this interface. This gives a lot of development flexibility and is a useful feature in Angular Forms.</p><p>There are several ways with some boilerplate to control decoration and usage. Let’s look at it and find the differences with an example.</p><h4>Example</h4><p>Let’s say we need to create a counter component and use its value through FormControl.</p><p>Counter component code with ControlValueAccessor:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c7c36f6c583dda8869df207cb4cf7376/href">https://medium.com/media/c7c36f6c583dda8869df207cb4cf7376/href</a></iframe><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/9575e11bb62dfb65c826ecda7745d4d3/href">https://medium.com/media/9575e11bb62dfb65c826ecda7745d4d3/href</a></iframe><p>A lot of code, yeah?</p><p>It’s too complicated to use in this case. What is better — to make an abstract class with ControlValueAccessor boilerplate and inherit from it. But that’s actually not necessary at this time.</p><p>Can we just make the component simpler? Sure:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/07417b52bb084f36ebb6ec868bb47087/href">https://medium.com/media/07417b52bb084f36ebb6ec868bb47087/href</a></iframe><p>Really simple component. But what restrictions do we get with this simplicity?</p><ul><li>First of all, we have to pass control directly, not with FormControlName or ngModel:</li></ul><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/616a3dbaee61bb3588a52169b9246d46/href">https://medium.com/media/616a3dbaee61bb3588a52169b9246d46/href</a></iframe><ul><li>Second, we lose template validators and can’t use it like this:</li></ul><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/9bcb1af975dc4b5fcfc4d68d7432e319/href">https://medium.com/media/9bcb1af975dc4b5fcfc4d68d7432e319/href</a></iframe><h4>Improvements</h4><p>How can we make our code better?</p><p>Let’s pass formControl directly to @Input for use as the Angular directive. But if we do this, there will be an error, — Error: No value accessor for form control with the unspecified name attribute. This error can be fixed with another directive ngDefaultControl:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e517ef321879fc30f86017d2db601439/href">https://medium.com/media/e517ef321879fc30f86017d2db601439/href</a></iframe><p>Now it works perfectly with template validators and has no errors.</p><p>Another trick is if the control is used inside a FormGroup — we have to pass control with a function. But instead of that, just use a pure pipe with no recalculation on every ChangeDetection pass. For example:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f18b806131ec26649eeb8fb2b54661e5/href">https://medium.com/media/f18b806131ec26649eeb8fb2b54661e5/href</a></iframe><p>Finally, our counter control becomes:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ae76728020c86f3223f7f9f06809a940/href">https://medium.com/media/ae76728020c86f3223f7f9f06809a940/href</a></iframe><p>Hope this article was helpful to you.</p><p>Thanks.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=da27f0a16639" width="1" height="1" alt=""><hr><p><a href="https://medium.com/better-programming/angular-with-controlvalueaccessor-and-without-less-boilerplate-da27f0a16639">When to Use Angular ControlValueAccessor and What’s the Difference Without It?</a> was originally published in <a href="https://betterprogramming.pub/">Better Programming</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Angular: Get Control in ControlValueAccessor]]></title>
            <link>https://levelup.gitconnected.com/angular-get-control-in-controlvalueaccessor-b7f09a485fba?source=rss-1d7d68a9fdf3------2</link>
            <guid isPermaLink="false">https://medium.com/p/b7f09a485fba</guid>
            <category><![CDATA[best-practices]]></category>
            <category><![CDATA[dependency-injection]]></category>
            <category><![CDATA[frontend-development]]></category>
            <category><![CDATA[angular]]></category>
            <category><![CDATA[forms]]></category>
            <dc:creator><![CDATA[Anton Marinenko]]></dc:creator>
            <pubDate>Tue, 12 Apr 2022 12:17:39 GMT</pubDate>
            <atom:updated>2022-04-17T11:43:47.272Z</atom:updated>
            <content:encoded><![CDATA[<h4>Angular Forms</h4><h4>How to get a reference to the control passed to your custom component without creating a new one.</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1WN9_4GYMWACSNfYGa08cA.jpeg" /></figure><p>This is an updated and improved article on getting a control into a <em>ControlValueAccessor</em> in Angular. (<a href="https://medium.com/@toha.marko/get-actual-control-in-controlvalueaccessor-e5bb3bb6710">Old one</a>)</p><p>When you have to deal with forms in Angular, — actually, you can’t go without <em>ControlValueAccessor</em> practice, because of its flexibility and functionality. You can create a control from any element in your application. That’s the power.</p><blockquote>There is a simple iteration for the component to become a control: provide <em>NG_VALUE_ACCESSOR </em>token value and implement <em>ControlValueAccessor</em> interface within it.</blockquote><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/17f46affe6bf292a12d23bbf5673443d/href">https://medium.com/media/17f46affe6bf292a12d23bbf5673443d/href</a></iframe><p>The component can now be used within <em>FormGroup </em>or simply as standalone control in the application.</p><p>And that’s the point of this article about is — how can we inject the control into the component?</p><p>First, let’s find out what kind of control directives we can pass to the component:</p><ul><li><strong>FormControl</strong></li><li><strong>FormControlName</strong></li><li><strong>NgModel</strong></li></ul><p>Next, how can we get these controls in the component? The solution is easy with Angular DI, — just inject <em>NgControl</em> reference. But, if you try to inject <em>NgControl </em>directly<em> </em>within<em> </em>the constructor, you will get an error: “<em>Error: NG0200: Circular dependency in DI detected…”</em>.</p><p>How can we solve this problem? Exactly, — we can inject <em>NgControl</em> in the <em>OnInit</em> lifecycle hook via <em>Injector </em>without any error.</p><p>Angular is super flexible!</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/672402af1433ae3a9c64d5b0a0ef5ea9/href">https://medium.com/media/672402af1433ae3a9c64d5b0a0ef5ea9/href</a></iframe><p>Now let’s recognize the kind of control we have. For this reason, I created a switch statement for a constructor definition of injected class:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4bfc9f5f55dd595c5b5b2b5fd32eb5a7/href">https://medium.com/media/4bfc9f5f55dd595c5b5b2b5fd32eb5a7/href</a></iframe><p>Finally, let’s make our component structure more logical and beautiful — put all this logic in a separate method. Final component here:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a58726b526c2e3539a90e5929c2746f9/href">https://medium.com/media/a58726b526c2e3539a90e5929c2746f9/href</a></iframe><p>That’s all for today. Thank you for your attention.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b7f09a485fba" width="1" height="1" alt=""><hr><p><a href="https://levelup.gitconnected.com/angular-get-control-in-controlvalueaccessor-b7f09a485fba">Angular: Get Control in ControlValueAccessor</a> was originally published in <a href="https://levelup.gitconnected.com/">Level Up Coding</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Angular: get applied validators list for the control]]></title>
            <link>https://medium.com/@toha.marko/angular-get-list-of-validators-from-the-control-d51dc16c0c3c?source=rss-1d7d68a9fdf3------2</link>
            <guid isPermaLink="false">https://medium.com/p/d51dc16c0c3c</guid>
            <category><![CDATA[angular]]></category>
            <category><![CDATA[validation]]></category>
            <category><![CDATA[typescript]]></category>
            <category><![CDATA[front-end-development]]></category>
            <category><![CDATA[dependency-injection]]></category>
            <dc:creator><![CDATA[Anton Marinenko]]></dc:creator>
            <pubDate>Sun, 27 Mar 2022 11:38:29 GMT</pubDate>
            <atom:updated>2022-03-27T14:50:35.473Z</atom:updated>
            <content:encoded><![CDATA[<h4>Angular Forms</h4><h4>A simple way to get validators list within ControlValueAccessor component</h4><p>Sometimes we get a simple type of task — get the list of validators for the current control. We can do that easily if this control was implemented in a separate component with ControlValueAccessor interface.</p><p>Angular provides the ability to use NG_VALIDATORS token and solve the described problem with a simple DI injection.</p><h4>Example</h4><p>We have a simple component app-input with ControlValueAccessor implementation:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/af2365931d1435297d05936625f283db/href">https://medium.com/media/af2365931d1435297d05936625f283db/href</a></iframe><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/068a7252f15a7e7a1e7808d5c59591dc/href">https://medium.com/media/068a7252f15a7e7a1e7808d5c59591dc/href</a></iframe><p>This simple trick allows you to access the current list of validators for the control. That’s it.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d51dc16c0c3c" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Angular: HttpContextToken — Handling HTTP Requests]]></title>
            <link>https://medium.com/better-programming/angular-tweaking-a-http-request-with-httpcontexttoken-41920f3d1e24?source=rss-1d7d68a9fdf3------2</link>
            <guid isPermaLink="false">https://medium.com/p/41920f3d1e24</guid>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[angular]]></category>
            <category><![CDATA[dependency-injection]]></category>
            <category><![CDATA[front-end-development]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Anton Marinenko]]></dc:creator>
            <pubDate>Sun, 13 Mar 2022 12:54:32 GMT</pubDate>
            <atom:updated>2022-04-05T19:12:33.634Z</atom:updated>
            <content:encoded><![CDATA[<h4>What’s for and usage example</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*mpyMxmHHNYHEySIHMuZ-FA.jpeg" /></figure><p>Quite often in the application, we need to handle some http requests with different conditions. And those conditions cause different logic in code.</p><p>Usually, in Angular, we do this in a class that implements the <a href="https://angular.io/api/common/http/HttpInterceptor">HttpInterceptor</a> interface. Of course, there are many standard practices with service injection and conditional checks. But we can also use the strength of Angular. Let’s use HttpContextToken.</p><blockquote>The purpose of HttpContextToken reveals in its name, — this token allows you to add additional data to the request context.</blockquote><h3>An Example</h3><p>Let’s say we have an application with server requests with authorization rights. And if we don’t have rights, the request is not gonna be sent. But also we have to take care of requests to several APIs that are open and do not require an authorization check.</p><p>One way to solve that problem is to have a list of open APIs and check every request URL to be included in this list. But that’s a little overhead there, let’s solve this problem with HttpContextToken.</p><p>We have very simple ApiInterceptor class with a dumb rights check:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/0a9c4745e8c36dedd426bc279a1a7251/href">https://medium.com/media/0a9c4745e8c36dedd426bc279a1a7251/href</a></iframe><p>And here is a service with requests:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d67ecfc19926d67020920c0ac30e46eb/href">https://medium.com/media/d67ecfc19926d67020920c0ac30e46eb/href</a></iframe><p>Now we need to modify our code with HttpContextToken. For that reason let’s create an instance of HttpContextToken token with default value false and use it inside the interceptor class.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/5338e1be5a66ecdd8bbdfd4285d84d90/href">https://medium.com/media/5338e1be5a66ecdd8bbdfd4285d84d90/href</a></iframe><p>With code request.context.get you can get params of the context. So, we did the main step — add a check for open APIs in the requests.</p><p>Now, if OPEN_API_HTTP_TOKEN token value is true, request will be invoked.</p><p>Let’s take the last step and modify our service by setting the token:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1d9896b5ec3c024f77f9f5657c20bb41/href">https://medium.com/media/1d9896b5ec3c024f77f9f5657c20bb41/href</a></iframe><p>That’s it! Now our application is ready to work with open APIs.</p><p>Hope you enjoyed this lesson, thank you, and stay with Angular.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=41920f3d1e24" width="1" height="1" alt=""><hr><p><a href="https://medium.com/better-programming/angular-tweaking-a-http-request-with-httpcontexttoken-41920f3d1e24">Angular: HttpContextToken — Handling HTTP Requests</a> was originally published in <a href="https://betterprogramming.pub/">Better Programming</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>