<?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[NgVerse - Medium]]></title>
        <description><![CDATA[Topics about Angular - Medium]]></description>
        <link>https://medium.com/ngverse?source=rss----5a3fc9f45fcc---4</link>
        <image>
            <url>https://cdn-images-1.medium.com/proxy/1*TGH72Nnw24QL3iV9IOm4VA.png</url>
            <title>NgVerse - Medium</title>
            <link>https://medium.com/ngverse?source=rss----5a3fc9f45fcc---4</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 17 Nov 2026 10:32:12 GMT</lastBuildDate>
        <atom:link href="https://medium.com/feed/ngverse" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[How to Handle State in a Custom Angular Select Component]]></title>
            <link>https://medium.com/ngverse/how-to-handle-state-in-a-custom-angular-select-component-560fa24fe415?source=rss----5a3fc9f45fcc---4</link>
            <guid isPermaLink="false">https://medium.com/p/560fa24fe415</guid>
            <category><![CDATA[state-management]]></category>
            <category><![CDATA[frontend]]></category>
            <category><![CDATA[angular]]></category>
            <category><![CDATA[open-source]]></category>
            <dc:creator><![CDATA[Nikolay Lazarov]]></dc:creator>
            <pubDate>Sat, 22 Mar 2025 15:47:36 GMT</pubDate>
            <atom:updated>2025-03-22T15:47:35.985Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*tOfKpGly3ORMh4n_V6cnlw.png" /></figure><blockquote>New open-source project in town check <a href="https://ui.ngverse.dev/">Ng-Verse!</a>, give it a star if you like it ;)</blockquote><p>In our<a href="https://medium.com/ngverse/custom-select-component-in-angular-best-practices-common-pitfalls-bd9400e7b3e3"> previous article</a>, we explored different ways to implement a select field in Angular. Now, let’s discuss how to share state between child components within a custom select component. There are multiple ways to approach this, each with its own advantages and trade-offs.</p><p><em>(For the sake of simplicity, the examples provided in this article are simplified but you can explore </em><a href="https://ui.ngverse.dev/doc/select"><em>Ng-Verse Select component</em></a><em> and check the full implementation)</em></p><h4>1. Injecting the Parent into the Child</h4><p>The easiest approach is to inject the parent component into the child and call the select method directly. This allows the child to notify the parent when an item is selected.</p><pre>@Component({<br>  selector: &#39;app-option&#39;,<br>  template: &#39;&lt;ng-content&gt;&lt;/ng-content&gt;&#39;,<br>  changeDetection: ChangeDetectionStrategy.OnPush,<br>  host: {<br>    &#39;(click)&#39;: &#39;onClick()&#39;,<br>  },<br>})<br>export class OptionComponent {<br>  value = input.required&lt;unknown&gt;();<br>  selected = signal(false);<br>  private readonly selectComponent = inject(SelectComponent);<br><br>  onClick() {<br>    this.selectComponent.selectOption(this);<br>  }<br>}<br><br>@Component({<br>  selector: &#39;app-select&#39;,<br>  template: `<br>    &lt;button (click)=&quot;open()&quot;&gt;<br>      @if (selectedOption()) {<br>        {{ selectedOption()?.value() }}<br>      } @else {<br>        Open select<br>      }<br>    &lt;/button&gt;<br>    @if (isOpen()) {<br>      &lt;div&gt;<br>        &lt;ng-content select=&quot;app-option&quot;&gt;&lt;/ng-content&gt;<br>      &lt;/div&gt;<br>    }<br>  `,<br>  changeDetection: ChangeDetectionStrategy.OnPush,<br>})<br>export class SelectComponent {<br>  isOpen = signal(false);<br>  selectedOption = signal&lt;OptionComponent | null&gt;(null);<br><br>  open() {<br>    this.isOpen.set(true);<br>  }<br><br>  selectOption(option: OptionComponent) {<br>    this.unselectPrevOption();<br>    this.selectedOption.set(option);<br>  }<br><br>  unselectPrevOption() {<br>    if (this.selectedOption()) {<br>      this.selectedOption()?.selected.set(false);<br>      this.selectedOption.set(null);<br>    }<br><br>  }<br>}</pre><p>This approach is straightforward and easy to understand, making it a great choice for most use cases but <strong>the downside is it introduces a tight coupling.<br></strong>Additionally, if you need to implement features such as selecting the first child on open, you will likely need to retrieve all child components using <strong>contentChildren()</strong> in the parent. However, this can lead to a circular dependency, requiring the use of forwardRef to properly resolve dependencies.</p><h3>2. Subscribing to Child Output in the Parent</h3><p>Another approach is for the parent to listen for an event emitted by the child using <strong>effect()</strong> in the constructor.</p><pre>@Component({<br>  selector: &#39;app-option&#39;,<br>  template: &#39;&lt;ng-content&gt;&lt;/ng-content&gt;&#39;,<br>  changeDetection: ChangeDetectionStrategy.OnPush,<br>  host: {<br>    &#39;(click)&#39;: &#39;onClick()&#39;,<br>  },<br>})<br>export class OptionComponent {<br>  value = input.required&lt;unknown&gt;();<br>  selected = signal(false);<br>  select = output();<br><br>  onClick() {<br>    this.select.emit();<br>  }<br>}<br><br>@Component({<br>  selector: &#39;app-select&#39;,<br>  template: `<br>    &lt;button (click)=&quot;open()&quot;&gt;<br>      @if (selectedOption()) {<br>        {{ selectedOption()?.value() }}<br>      } @else {<br>        Open select<br>      }<br>    &lt;/button&gt;<br>    @if (isOpen()) {<br>      &lt;div&gt;<br>        &lt;ng-content select=&quot;app-option&quot;&gt;&lt;/ng-content&gt;<br>      &lt;/div&gt;<br>    }<br>  `,<br>  changeDetection: ChangeDetectionStrategy.OnPush,<br>})<br>export class SelectComponent implements OnDestroy {<br>  isOpen = signal(false);<br>  selectedOption = signal&lt;OptionComponent | null&gt;(null);<br><br>  options = contentChildren(OptionComponent);<br><br>  subs: Subscription | null = null;<br><br>  constructor() {<br>    effect(() =&gt; {<br>      this.subs?.unsubscribe();<br>      this.subs = new Subscription();<br><br>      for(const option of this.options()) {<br>        this.subs.add(option.select.subscribe(() =&gt; {<br>          this.selectOption(option);<br>          this.isOpen.set(false);<br>        }));<br>      }<br>    });<br>  }<br><br>  open() {<br>    this.isOpen.set(true);<br>  }<br><br>  ngOnDestroy() {<br>    this.subs?.unsubscribe();<br>    this.subs = null;<br>  }<br><br>  selectOption(option: OptionComponent) {<br>    this.unselectPrevOption();<br>    this.selectedOption.set(option)<br>  }<br><br>  unselectPrevOption() {<br>    if (this.selectedOption()) {<br>      this.selectedOption()?.selected.set(false);<br>      this.selectedOption.set(null);<br>    }<br><br>  }<br>}</pre><p>This method ensures better encapsulation since the child doesn’t directly access the parent. However, it requires additional event handling in the parent component and storing all subscriptions in the Subscription object to prevent memory leaks, of course, we can make it clever and subscribe to newly added items only but is it worth the complexity?</p><h3>3. Using a Shared State Service</h3><p>The most scalable but complex approach is to use a shared state service. The service will hold the selected item, and both the parent and child will interact with it.</p><pre>@Component({<br>  selector: &#39;app-option&#39;,<br>  template: &#39;&lt;ng-content&gt;&lt;/ng-content&gt;&#39;,<br>  changeDetection: ChangeDetectionStrategy.OnPush,<br>  host: {<br>    &#39;(click)&#39;: &#39;onClick()&#39;,<br>  },<br>})<br>export class OptionComponent {<br>  value = input.required&lt;unknown&gt;();<br>  selected = signal(false);<br>  private selectService = inject(SelectService);<br><br>  onClick() {<br>    this.selectService.select(this)<br>  }<br>}<br><br><br>@Injectable()<br>export class SelectService {<br>  selected = signal&lt;OptionComponent | null&gt;(null);<br>  isOpen = signal(false)<br><br>  select(option: OptionComponent) {<br>    this.selected.set(option);<br>    this.close();<br>  }<br><br>  unselectPrev() {<br>    if (this.selected()) {<br>      this.selected()?.selected.set(false);<br>      this.selected.set(null);<br>    }<br>  }<br><br>  open() {<br>    this.isOpen.set(true)<br>  }<br><br>  close () {<br>    this.isOpen.set(false);<br>  }<br>}<br><br>@Component({<br>  selector: &#39;app-select&#39;,<br>  template: `<br>    &lt;button (click)=&quot;open()&quot;&gt;<br>      @if (selectedOption()) {<br>        {{ selectedOption()?.value() }}<br>      } @else {<br>        Open select<br>      }<br>    &lt;/button&gt;<br>    @if (isOpen()) {<br>      &lt;div&gt;<br>        &lt;ng-content select=&quot;app-option&quot;&gt;&lt;/ng-content&gt;<br>      &lt;/div&gt;<br>    }<br>  `,<br>  changeDetection: ChangeDetectionStrategy.OnPush,<br>  providers: [<br>    SelectService<br>  ]<br>})<br>export class SelectComponent {<br>  private selectService = inject(SelectService);<br>  selectedOption = this.selectService.selected;<br>  isOpen = this.selectService.isOpen;<br><br>  open() {<br>    this.selectService.open();<br>  }<br>}</pre><p>This approach allows for a more decoupled architecture but introduces additional complexity.</p><h3>Choosing the Right Approach</h3><p>There is no single “best” solution. Each approach has its own trade-offs:</p><ul><li><strong>Injecting the parent into the child</strong> is the simplest and most straightforward approach.</li><li><strong>Subscribing to child outputs</strong> provides better encapsulation but can have performance issues.</li><li><strong>Using a shared state service</strong> is the most flexible but adds complexity.</li></ul><h3>What Did Ng-Verse Choose?</h3><p>In Ng-Verse, we decided to use the first approach — injecting the parent into the child — because it was the easiest to understand and avoided unnecessary complexity.</p><h3>But what is Ng-Verse?</h3><p><a href="https://ui.ngverse.dev/">Ng-Verse</a> is a collection of feature-rich Angular components, directives, and utilities designed for flexibility and customization. Unlike traditional UI libraries that you install as runtime dependencies, Ng-Verse is added as a development dependency and injects the component source code directly into your project, allowing full control and modification using schematics.</p><h3>Key Features of Ng-Verse:</h3><ul><li><strong>Zoneless</strong>: No reliance on zone.js.</li><li><strong>Fully Customizable</strong>: Modify the source code as needed.</li><li><strong>Accessibility</strong>: Includes keyboard navigation and focus management.</li><li><strong>Modular</strong>: Only add the components you need.</li></ul><h3>Why This Approach?</h3><p>Many UI libraries limit customization. With Ng-Verse, you get full control over the component’s behavior and styling. For example, when implementing the select component, we wanted an intuitive, lightweight solution. Injecting the parent into the child was the simplest and most effective approach.</p><p>By understanding these different methods of state management, you can choose the approach that best fits your project’s needs!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=560fa24fe415" width="1" height="1" alt=""><hr><p><a href="https://medium.com/ngverse/how-to-handle-state-in-a-custom-angular-select-component-560fa24fe415">How to Handle State in a Custom Angular Select Component</a> was originally published in <a href="https://medium.com/ngverse">NgVerse</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[New Angular animation library @ngverse/motion]]></title>
            <link>https://medium.com/ngverse/new-angular-animation-library-ngverse-motion-c7ee7762f0b9?source=rss----5a3fc9f45fcc---4</link>
            <guid isPermaLink="false">https://medium.com/p/c7ee7762f0b9</guid>
            <category><![CDATA[angular-animations]]></category>
            <category><![CDATA[angular]]></category>
            <category><![CDATA[typescript]]></category>
            <category><![CDATA[angular-library]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Luka Onikadze]]></dc:creator>
            <pubDate>Mon, 17 Mar 2025 18:18:53 GMT</pubDate>
            <atom:updated>2025-03-17T18:18:53.806Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/700/1*Rg_0B8XUnDJtvL-oswCsJw.png" /></figure><p>Angular is a feature-rich framework that comes with essential functionalities like routing, signals, and animations. Among these, the animations module stands out as a powerful and flexible tool, enabling developers to create stunning visual effects that enhance user experience.</p><h3>The Challenge of Defining Animations</h3><p>While Angular provides the infrastructure for animations, it does not include predefined animations out of the box. This means that developers must determine how animations should behave — such as specifying which properties to animate, how they should change over time, and the duration of the animation. For instance, if you want to create a fade-in effect, you need to define the opacity transition manually.</p><h3>Existing Animation Libraries</h3><p>Fortunately, several battle-tested animation libraries are available, such as <a href="https://animate.style/">Animate.css</a>. These libraries provide well-defined animations that work as described. However, they are not natively integrated with Angular’s animation system, making it difficult to leverage Angular-specific features like triggers, transitions, and customization.</p><h3>Introducing @ngverse/motion</h3><p>This is where <a href="https://motion.ngverse.dev/">@ngverse/motion</a> comes into play. It brings popular animations into Angular’s animation ecosystem, allowing you to use them seamlessly within your application while retaining the full power of Angular’s animation features.</p><p>For example, if you want to apply a fadeIn animation when an element enters the viewport, you can achieve it with minimal effort:</p><pre>import { Component } from &#39;@angular/core&#39;;<br>import { fadeInOnEnter } from &#39;@ngverse/motion&#39;;<br><br>@Component({<br>  selector: &#39;app-example&#39;,<br>  template: `&lt;div [@fadeInOnEnter]&gt;Hello, Angular Animations!&lt;/div&gt;`,<br>  animations: [fadeInOnEnter()]<br>})<br>export class ExampleComponent {}</pre><p>This approach ensures that animations are well-structured, reusable, and fully compatible with Angular’s animation triggers.</p><h3>Why Use @ngverse/motion?</h3><ul><li><strong>Native Angular Animations</strong>: Fully integrated with Angular’s animation system, making it easy to use triggers, transitions, and event-based animations.</li><li><strong>Simplified Implementation</strong>: No need to manually define common animations like fade-in, slide-in, or bounce.</li><li><strong>Customizable</strong>: Animations can be fine-tuned to match the exact requirements of your application.</li><li><strong>Performance Optimized</strong>: Uses Angular’s animation engine, ensuring smooth and efficient rendering.</li></ul><p>Check out more on official <a href="https://motion.ngverse.dev/">docs</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c7ee7762f0b9" width="1" height="1" alt=""><hr><p><a href="https://medium.com/ngverse/new-angular-animation-library-ngverse-motion-c7ee7762f0b9">New Angular animation library @ngverse/motion</a> was originally published in <a href="https://medium.com/ngverse">NgVerse</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Custom Select Component in Angular: Best Practices & Common Pitfalls]]></title>
            <link>https://medium.com/ngverse/custom-select-component-in-angular-best-practices-common-pitfalls-bd9400e7b3e3?source=rss----5a3fc9f45fcc---4</link>
            <guid isPermaLink="false">https://medium.com/p/bd9400e7b3e3</guid>
            <category><![CDATA[component-libraries]]></category>
            <category><![CDATA[angular]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Nikolay Lazarov]]></dc:creator>
            <pubDate>Mon, 17 Feb 2025 18:15:58 GMT</pubDate>
            <atom:updated>2025-03-22T14:47:54.175Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*75N4iOQrJ4czvsl1feTlsQ.png" /></figure><blockquote>New open-source project in town check <a href="https://ui.ngverse.dev/">Ng-Verse</a>!, give it a star if you like it ;)</blockquote><p>In this article, we’ll explore different ways to provide <strong>options</strong> in a Select component and determine the best approach.</p><p><strong>For the sake of simplicity, the examples provided do not include CSS styling or implement </strong><strong>ControlValueAccessor, but these can be easily added for full integration with Angular forms.</strong></p><h3>Three Approaches to Passing Options</h3><h3>1. Using Content Projection</h3><p>Content projection allows developers to <strong>pass option elements directly inside the Select component</strong>, making it highly customizable while keeping the template clean.</p><pre>&lt;app-select [(ngModel)]=&quot;selectedValue&quot;&gt;<br>  &lt;app-option [value]=&quot;&#39;Option 1&#39;&quot;&gt;Option 1&lt;/app-option&gt;<br>  &lt;app-option [value]=&quot;&#39;Option 2&#39;&quot;&gt;Option 2&lt;/app-option&gt;<br>&lt;/app-select&gt;</pre><pre>@Component({<br>  selector: &#39;app-select&#39;,<br>  template: `<br>    &lt;div (click)=&quot;toggleDropdown()&quot;&gt;<br>      {{ selected() || &#39;Select an option&#39; }}<br>    &lt;/div&gt;<br>    @if (isOpen()) {<br>      &lt;ng-content&gt;&lt;/ng-content&gt;<br>    }<br>  `,<br>  standalone: true<br>})<br>export class SelectComponent {<br>  private selectedValue = signal&lt;string | null&gt;(null);<br>  isOpen = signal(false);<br><br>  options = contentChildren(OptionComponent);<br><br>  toggleDropdown() {<br>    this.isOpen.set(!this.isOpen());<br>  }<br><br>  selected = computed(() =&gt; this.options()?.find(opt =&gt; opt.value === this.selectedValue())?.label || null);<br>}</pre><pre>@Component({<br>  selector: &#39;app-option&#39;,<br>  template: `&lt;div (click)=&quot;select()&quot;&gt;&lt;ng-content&gt;&lt;/ng-content&gt;&lt;/div&gt;`,<br>  standalone: true<br>})<br>export class OptionComponent {<br>  value = input.required&lt;string&gt;();<br>}</pre><h3>2. Passing Options as an Input Property</h3><p>This approach allows passing an array of options as an input property, keeping the markup simple and the logic contained within the component.</p><pre>&lt;app-select [items]=&quot;options&quot; [(value)]=&quot;selectedValue&quot;&gt;&lt;/app-select&gt;</pre><pre>@Component({<br>  selector: &#39;app-select&#39;,<br>  template: `<br>    &lt;div (click)=&quot;toggleDropdown()&quot;&gt;<br>      {{ selected() || &#39;Select an option&#39; }}<br>    &lt;/div&gt;<br>    @if (isOpen()) {<br>      &lt;ul&gt;<br>        @for (item of items; track item) {<br>          &lt;li (click)=&quot;select(item)&quot;&gt;{{ item.label }}&lt;/li&gt;<br>        }<br>      &lt;/ul&gt;<br>    }<br>  `,<br>  standalone: true<br>})<br>export class SelectComponent {<br>  items = input&lt;{ value: string; label: string }[]&gt;([]);<br>  value = model&lt;string | null&gt;(null);<br><br>  isOpen = signal(false);<br><br>  selected = computed(() =&gt; this.items.find(opt =&gt; opt.value === this.value())?.label || null);<br><br>  toggleDropdown() {<br>    this.isOpen.set(!this.isOpen());<br>  }<br><br>  select(item: any) {<br>    this.value.set(item.value);<br>  }<br>}</pre><h3>3. Using a TemplateRef for Custom Option Rendering</h3><p>With this approach, the consumer can define a custom template for rendering options, allowing for more flexible UI customization.</p><pre>&lt;app-select [items]=&quot;options&quot; [(selectedValue)]=&quot;value&quot;&gt;<br>  &lt;ng-template let-item&gt;<br>    &lt;div class=&quot;custom-option&quot;&gt;<br>      &lt;span&gt;{{ item.label }}&lt;/span&gt; - &lt;strong&gt;{{ item.value }}&lt;/strong&gt;<br>    &lt;/div&gt;<br>  &lt;/ng-template&gt;<br>&lt;/app-select&gt;</pre><pre>@Component({<br>  selector: &#39;app-select&#39;,<br>  template: `<br>    &lt;div (click)=&quot;toggleDropdown()&quot;&gt;<br>      {{ selected() || &#39;Select an option&#39; }}<br>    &lt;/div&gt;<br>    @if (isOpen()) {<br>      &lt;ul&gt;<br>        @for (item of items(); track item.value) {<br>          &lt;li (click)=&quot;select(item)&quot;&gt;<br>            @if (optionTemplate()) {<br>                &lt;ng-container<br>                  [ngTemplateOutlet]=&quot;optionTemplate()!&quot;<br>                  [ngTemplateOutletContext]=&quot;{ $implicit: item }&quot;&gt;<br>                &lt;/ng-container&gt;<br>            }  @else {<br>              {{ item.label }}<br>            }<br>          &lt;/li&gt;<br>        }<br>      &lt;/ul&gt;<br>    }<br>  `,<br>  standalone: true,<br>  imports: [NgTemplateOutlet],<br>})<br>export class SelectComponent {<br>  items = input&lt;{ value: string; label: string }[]&gt;([]);<br>  optionTemplate = contentChild&lt;TemplateRef&lt;unknown&gt; | undefined | null&gt;(TemplateRef);<br>  isOpen = signal(false);<br>  selectedValue = model(null);<br><br>  selected = computed(() =&gt; {<br>    const selectedItem = this.items().find(<br>      (opt) =&gt; opt.value === this.selectedValue()<br>    );<br>    return selectedItem ? selectedItem.label : null;<br>  });<br><br>  toggleDropdown() {<br>    this.isOpen.set(!this.isOpen());<br>  }<br><br>  select(item: any) {<br>    this.selectedValue.set(item.value);<br>  }</pre><h4>Content Projection</h4><p>✅ <strong>Pros:</strong></p><ul><li><strong>Easier to use</strong> — Developers can directly place &lt;app-option&gt; components inside &lt;app-select&gt; without complex bindings.</li><li><strong>Highly flexible</strong> — Allows for full customization of each option’s structure and styling.</li></ul><p>❌ <strong>Cons:</strong></p><ul><li><strong>Event communication between parent and child</strong> — Transferring the selected state between &lt;app-select&gt; and its projected &lt;app-option&gt; components requires extra event handling.</li><li><strong>More boilerplate</strong> — Each option must be wrapped in a dedicated OptionComponent, which can feel verbose for simple cases.</li></ul><h4>Passing Options as an Array input</h4><p>✅ <strong>Pros:</strong></p><ul><li><strong>Simple to implement and use</strong> — Developers only need to pass an array of objects ({ value, label }) without defining additional components.</li><li><strong>Maintains semantic HTML</strong> — You can use &lt;ul&gt;&lt;li&gt; structures, improving accessibility and SEO.</li></ul><p>❌ <strong>Cons:</strong></p><ul><li><strong>i18n challenges</strong> — Since options are passed as static text, translating them requires either re-rendering the list when the language changes or embedding a translation mechanism inside the component, leading to <strong>tight coupling</strong>.</li><li><strong>Less control over styling</strong> — Developers cannot easily customize individual option elements beyond standard bindings.</li></ul><h4>Using a TemplateRef for Custom Rendering</h4><p>✅ <strong>Pros:</strong></p><ul><li><strong>Provides flexibility</strong> — You can define a fully custom template while keeping a default rendering fallback.</li><li><strong>Maintains semantic HTML</strong> — You can use &lt;ul&gt;&lt;li&gt; structures, improving accessibility and SEO.</li><li><strong>Optional customization</strong> — If no template is provided, the component can default to rendering the label property.</li></ul><p>❌ <strong>Cons:</strong></p><ul><li><strong>Complex to use</strong> — Requires developers to understand TemplateRef and ngTemplateOutlet, making it harder for beginners</li><li><strong>Less popular approach</strong> — Not widely used in most Angular UI libraries, meaning developers might struggle to adapt</li><li><strong>Can feel over-engineered</strong> — For simple dropdowns, passing items as an array is often sufficient.</li></ul><h3>Final Verdict: Content Projection Wins</h3><p>While each approach has its trade-offs, <strong>content projection</strong> strikes the best balance between <strong>ease of use and flexibility</strong>. Although handling state transfer requires additional logic, the ability to fully control the structure and styling of options makes it the most <strong>maintainable and customizable</strong> approach in the long run.</p><h3>Conclusion</h3><p>Building a high-quality Select component in Angular requires a thoughtful approach to customization and maintainability. <strong>By using content projection and Angular Signals, we can create a Select component that is flexible, powerful, and easy to use.</strong> Whether you’re a junior developer learning Angular or an experienced developer building scalable UIs, this approach ensures a strong foundation for future-proof component design.</p><p>If you found this article helpful, stay tuned for my next deep dive, where we’ll explore different approaches for handling communication between the <strong>Select</strong> component and its options. We’ll break down various techniques along with their pros and cons.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=bd9400e7b3e3" width="1" height="1" alt=""><hr><p><a href="https://medium.com/ngverse/custom-select-component-in-angular-best-practices-common-pitfalls-bd9400e7b3e3">Custom Select Component in Angular: Best Practices &amp; Common Pitfalls</a> was originally published in <a href="https://medium.com/ngverse">NgVerse</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Ng-Verse: A Perfect Learning Tool for Junior and New Angular Developers]]></title>
            <link>https://medium.com/ngverse/ng-verse-a-perfect-learning-tool-for-junior-and-new-angular-developers-b5f1f90bc8d9?source=rss----5a3fc9f45fcc---4</link>
            <guid isPermaLink="false">https://medium.com/p/b5f1f90bc8d9</guid>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[angular]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[junior-developer]]></category>
            <dc:creator><![CDATA[Nikolay Lazarov]]></dc:creator>
            <pubDate>Mon, 10 Feb 2025 07:30:16 GMT</pubDate>
            <atom:updated>2025-03-22T14:46:50.868Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gWLYeVF5-05rZH4tQjtIhw.png" /></figure><blockquote>New open-source project in town check <a href="https://ui.ngverse.dev/">Ng-Verse</a>!, give it a star if you like it ;)</blockquote><p>If you’re a junior developer or new to the Angular ecosystem, getting started with building scalable, maintainable components can feel overwhelming. Many UI libraries are either too complex or too rigid, making it difficult to learn best practices while still having the flexibility to experiment. This is where <strong>Ng-Verse</strong> comes in — not just as a UI library, but as a valuable learning tool that helps you write clean, well-structured Angular components while keeping up with the latest best practices.</p><h3>Learn to Write Maintainable and Scalable Components</h3><p>One of the biggest challenges junior developers face is understanding how to write <strong>maintainable and reusable</strong> components. <a href="https://ui.ngverse.dev/">Ng-Verse</a> follows a <strong>clean architecture</strong> that ensures every component is easy to understand, extend, and customize. By using Ng-Verse, you can explore real-world examples of properly structured Angular components and learn how to build your own in a modular and scalable way.</p><h3>Great for New Angular Developers</h3><p>If you’re new to Angular, <a href="https://ui.ngverse.dev/">Ng-Verse</a> provides an excellent foundation to get familiar with modern Angular development. Instead of working with outdated practices or bloated libraries, you’ll be learning from <strong>well-designed components that follow Angular’s latest APIs and best practices</strong>. This gives you a strong starting point for building professional-grade Angular applications.</p><h3>Easy to Understand, Regardless of Experience Level</h3><p>At Ng-Verse, we strive to make our components as <strong>simple and intuitive as possible</strong>, ensuring that both junior and senior developers can easily work with them. You don’t need to be an Angular expert to understand how our components are built. The codebase is clean and structured, allowing you to quickly grasp how things work, make modifications, and extend functionality as needed.</p><h3>Built with Angular’s Latest APIs</h3><p>Ng-Verse keeps up with the latest advancements in Angular, utilizing features such as:<br>✅ <strong>Signals</strong> — a modern way to manage reactivity in Angular.<br>✅ <strong>Standalone Components</strong> — making modules optional and simplifying component management.<br>✅ <strong>Minimal RxJS Usage</strong> — avoiding unnecessary complexity by limiting the use of RxJS where possible.<br>✅ <strong>Zoneless Support</strong> — ensuring better performance by reducing reliance on Angular’s Zone.js, making change detection more efficient and improving application responsiveness.</p><p>By working with these modern APIs, you’ll be learning Angular the right way — aligned with its future direction.</p><h3>Adapting to Angular’s Future (Without Decorators)</h3><p>It seems that <strong>Angular’s future is shifting away from decorators</strong>, and at Ng-Verse, we are preparing for that change. Wherever possible, we are <strong>reducing the reliance on decorators</strong>, making the components easier to adapt and ensuring that you’re learning Angular in a future-proof way.</p><h3>Even If Ng-Verse Isn’t a Perfect Fit, It’s a Strong Foundation</h3><p>While <a href="https://www.ng-verse.dev/">Ng-Verse</a> may not cover <strong>every possible use case</strong>, it still provides a <strong>solid foundation</strong> for anyone looking to build and extend Angular components. If you find that a component doesn’t fully meet your needs, you can <strong>extend and modify it</strong> rather than starting from scratch. This saves development time while giving you full control over customization.</p><h3>Conclusion</h3><p><a href="https://ui.ngverse.dev/">Ng-Verse</a> isn’t just another UI library — it’s a <strong>learning tool, a strong foundation, and a modern approach to Angular development</strong>. Whether you’re a junior developer learning how to write maintainable components or an experienced developer looking to keep up with Angular’s latest APIs, Ng-Verse has something to offer. By using Ng-Verse, you’re not just adopting a UI library — you’re investing in <strong>clean, scalable, and future-proof Angular development</strong>. 🚀</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b5f1f90bc8d9" width="1" height="1" alt=""><hr><p><a href="https://medium.com/ngverse/ng-verse-a-perfect-learning-tool-for-junior-and-new-angular-developers-b5f1f90bc8d9">Ng-Verse: A Perfect Learning Tool for Junior and New Angular Developers</a> was originally published in <a href="https://medium.com/ngverse">NgVerse</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Building Angular UI Like a Pro: Why Ng-Verse is Your New Best Friend]]></title>
            <link>https://medium.com/ngverse/building-angular-ui-like-a-pro-why-ng-verse-is-your-new-best-friend-3ed071aad777?source=rss----5a3fc9f45fcc---4</link>
            <guid isPermaLink="false">https://medium.com/p/3ed071aad777</guid>
            <dc:creator><![CDATA[Nikolay Lazarov]]></dc:creator>
            <pubDate>Sat, 08 Feb 2025 18:16:04 GMT</pubDate>
            <atom:updated>2025-03-22T14:45:50.711Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*K1RPi7sVtYQG2RBKRqMSEw.png" /></figure><blockquote>New open-source project in town check <a href="https://ui.ngverse.dev/">Ng-Verse</a>!, give it a star if you like it ;)</blockquote><p>Ng-Verse is an <strong>open-source</strong> Angular UI library designed to <strong>simplify building and customizing user interfaces</strong>. Unlike traditional UI libraries that restrict customization with pre-defined, rigid components, Ng-Verse <strong>provides fully functional, customizable components</strong> — giving developers complete control over both <strong>design and functionality</strong>.</p><h3>How Ng-Verse Works</h3><p>Ng-Verse is not just another UI library you install as a dependency. Instead, it follows <strong>another approach</strong>:<br>✅ <strong>Direct Integration</strong> — You add the source code of the components, directives, and pipes directly into your project — using schematics or by copy-pasting.<br>✅ <strong>Full Customization</strong> — Since the components are part of your codebase, you can modify their styles, behavior, and structure without limitations.<br>✅ <strong>Feature-Rich Components</strong> — From <strong>basic inputs and dropdowns</strong> to <strong>complex accordions and tabs</strong>, each component is designed to be highly flexible and <strong>maintainable.</strong></p><p>This <strong>no-dependency</strong> approach ensures that your UI remains <strong>fully adaptable</strong> to your needs. Whether you’re a <strong>junior developer learning Angular</strong> or an experienced engineer looking for a <strong>clean, maintainable</strong> component architecture, Ng-Verse<strong> provides the flexibility you need to build beautiful, efficient UIs</strong>.</p><h3>Getting started with Ng-Verse is quick and easy!</h3><p>1️⃣ <strong>Install </strong>Ng-Verse using Angular CLI:</p><pre>ng add ng-verse</pre><p>2️⃣ <strong>Generate a Component</strong> (e.g., a button):</p><pre>ng g ng-verse:element button</pre><p>Please check the <a href="https://ui.ngverse.dev/doc/installation">installation </a>page for more info.</p><h3>Why You Should Consider Ng-Verse</h3><h4>1. Freedom to Customize with Full Source Code Access</h4><p>Ng-Verse’s open-source nature and full access to source code provide a level of customization that few libraries offer. You can directly modify components to fit your project’s specific requirements, whether it’s altering styles, adding new functionality, or creating entirely new components. The ability to make these changes without restrictions makes Ng-Verse a powerful tool for developers who need flexibility.</p><h4>2. A Clean and Maintainable Codebase</h4><p>Ng-Verse follows a clean, modular approach to writing components, making them easy to integrate and customize within your application. Built with Angular’s latest features, it leverages zoneless change detection, signals, and standalone components, ensuring optimal performance and reactivity. The components are designed with best practices, making your codebase maintainable and scalable as your project grows. Whether you’re working on a small application or a large enterprise project, Ng-Verse provides a modern, efficient, and future-proof UI solution</p><h4>3. Reliability with Built-in Unit Tests</h4><p>Every component in Ng-Verse comes with unit tests, ensuring they work as expected and reducing the likelihood of bugs when integrating or modifying components. The tests also make it easier to maintain code quality and stability as you customize the components to fit your project.</p><h4>4. Community Contributions and Collaboration</h4><p>As an open-source project, Ng-Verse benefits from contributions from the development community. This ensures that the library remains up-to-date with the latest trends and best practices in UI development. You can also contribute to the library, improving it for everyone and fostering a sense of collaboration within the developer community.</p><h4>5. A Great Learning Opportunity for Junior Developers</h4><p><a href="https://ui.ngverse.dev/">Ng-Verse</a> is not only a powerful tool for experienced developers but also a fantastic resource for junior developers looking to sharpen their skills. By exploring and using it, junior developers can gain valuable insights into how well-designed components are structured and written. The library follows best practices for clean, maintainable code, which provides an excellent learning opportunity. Junior developers can study the components, see how they are modularized, and learn how to write reusable, scalable, and customizable UI elements. Additionally, the included unit tests offer a chance to understand how to properly test components, which is crucial for writing robust, production-quality code.</p><h3>Conclusion</h3><p>Ng-Verse is a powerful Angular UI library that stands out due to its open-source nature, clean approach to component development, and comprehensive feature set. With customizable, fully featured components that come with unit tests and a consistent design system, Ng-Verse offers everything you need to build professional, reliable, and scalable applications. Its open-source model and direct access to source code make it an ideal choice for developers who need flexibility and want to maintain full control over their UI components. If you’re looking for a modern, well-tested, and highly customizable UI library for Angular, Ng-Verse is a compelling option that you should definitely consider.</p><p>You can <strong>give it a go</strong> by visiting <a href="https://ui.ngverse.dev/"><strong>Ng-Verse’s official website</strong></a> and exploring <strong>27+ powerful components.</strong></p><p>Check it out and start building today!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3ed071aad777" width="1" height="1" alt=""><hr><p><a href="https://medium.com/ngverse/building-angular-ui-like-a-pro-why-ng-verse-is-your-new-best-friend-3ed071aad777">Building Angular UI Like a Pro: Why Ng-Verse is Your New Best Friend</a> was originally published in <a href="https://medium.com/ngverse">NgVerse</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Make LocalStorage SSR Compatible in Angular]]></title>
            <link>https://medium.com/ngverse/make-localstorage-ssr-compatible-in-angular-431d7ce5714e?source=rss----5a3fc9f45fcc---4</link>
            <guid isPermaLink="false">https://medium.com/p/431d7ce5714e</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[angular]]></category>
            <category><![CDATA[angular-components]]></category>
            <category><![CDATA[typescript]]></category>
            <dc:creator><![CDATA[Luka Onikadze]]></dc:creator>
            <pubDate>Fri, 07 Feb 2025 10:45:23 GMT</pubDate>
            <atom:updated>2025-02-07T10:51:17.853Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Kr6DECRGgl28Grw8Oc-a7Q.png" /></figure><blockquote>New open-source project in town check <a href="https://www.ng-verse.dev/">Ng-Verse</a>!, give it a star if you like it ;)</blockquote><p>The Angular team is strongly advocating for Server-Side Rendering (SSR). They continue to release new SSR features with every Angular update, which means your code should always be compatible with SSR. While Angular automatically handles some SSR compatibility issues, others require manual intervention. One common issue is the use of localStorage. If you use localStorage in your codebase and run it in an SSR environment, you will encounter a compilation error similar to the following:</p><pre>ERROR ReferenceError: localStorage is not defined</pre><p>To fix this error, you need to check whether the code is running in a browser using the isPlatformBrowser method, and then execute the localStorage code accordingly. Although this solution works, it requires you to add checks every time you use localStorage.</p><p>A better approach is to create a LocalStorageService. During the service&#39;s initialization, you can detect whether the application is running in an SSR environment. If it is, you mock the localStorage. Otherwise, you use the native localStorage. This approach provides several benefits:</p><ul><li>You no longer need to manually check the runtime environment wherever you use localStorage.</li><li>You avoid potential bugs caused by runtime errors related to localStorage.</li></ul><p>Let me explain how it works.</p><h3>Implementation</h3><p>I am going to use the <a href="https://www.ng-verse.dev/doc/local-storage">Ng-Verse/LocalStorage</a> implementation. Here’s what it looks like:</p><pre>import { DOCUMENT, isPlatformBrowser } from &#39;@angular/common&#39;;<br>import { inject, Injectable, InjectionToken, PLATFORM_ID } from &#39;@angular/core&#39;;<br><br>function mockLocalStorage(): Storage {<br>  return {<br>    length: 0,<br>    key: () =&gt; null,<br>    getItem: () =&gt; null,<br>    setItem: () =&gt; null,<br>    removeItem: () =&gt; null,<br>    clear: () =&gt; null,<br>  };<br>}<br><br>export const LOCAL_STORAGE_TOKEN = new InjectionToken&lt;Storage&gt;(<br>  &#39;LOCAL_STORAGE_TOKEN&#39;,<br>  {<br>    factory: () =&gt; {<br>      const platformId = inject(PLATFORM_ID);<br>      const isBrowser = isPlatformBrowser(platformId);<br>      const document = inject(DOCUMENT);<br><br>      if (isBrowser) {<br>        return document.defaultView?.localStorage ?? mockLocalStorage();<br>      } else {<br>        return mockLocalStorage();<br>      }<br>    },<br>  }<br>);<br><br>@Injectable({<br>  providedIn: &#39;root&#39;,<br>})<br>export class LocalStorageService implements Storage {<br>  private _storage = inject(LOCAL_STORAGE_TOKEN);<br><br>  readonly enabled = isPlatformBrowser(inject(PLATFORM_ID));<br><br>  get length() {<br>    return this._storage.length;<br>  }<br><br>  clear() {<br>    this._storage.clear();<br>  }<br>  getItem(key: string) {<br>    return this._storage.getItem(key);<br>  }<br>  key(index: number) {<br>    return this._storage.key(index);<br>  }<br>  removeItem(key: string): void {<br>    this._storage.removeItem(key);<br>  }<br>  setItem(key: string, value: string): void {<br>    this._storage.setItem(key, value);<br>  }<br>}</pre><p>This LocalStorageService implements the <a href="https://developer.mozilla.org/en-US/docs/Web/API/Storage">Storage</a> interface, which includes all the methods and properties of the native localStorage. During its creation, we check if the application is running in a browser or on the server. If it’s running in a browser, we return the native localStorage. Otherwise, we return a mockStorage object that implements all methods of the Storage interface but performs no operations.</p><p>This prevents any compilation or runtime errors. For example, if you call getItem on localStorage in an SSR environment, it will simply return undefined. You are likely already handling such cases by checking for a null or undefined value in your application logic.</p><p>Additionally, if you need to apply different logic between SSR and browser environments, you can use the enabled property of LocalStorageService. This property returns a boolean indicating whether native localStorage is available.</p><p>Here’s a quick example of the usage oflocalStorageService:</p><pre>localStorage = inject(LocalStorageService);<br><br>ngOnInit() {<br>  const theme = this.localStorage.getItem(&#39;theme&#39;);<br>  if (!theme) {<br>    console.warn(&#39;Theme is not saved, saving the default one!&#39;);<br>    this.localStorage.setItem(&#39;theme&#39;, &#39;dark&#39;);<br>  }<br>}</pre><p>This approach simplifies your code and ensures SSR compatibility by handling localStorage in a centralized manner.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=431d7ce5714e" width="1" height="1" alt=""><hr><p><a href="https://medium.com/ngverse/make-localstorage-ssr-compatible-in-angular-431d7ce5714e">Make LocalStorage SSR Compatible in Angular</a> was originally published in <a href="https://medium.com/ngverse">NgVerse</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>