<?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 Sachith Rukshan on Medium]]></title>
        <description><![CDATA[Stories by Sachith Rukshan on Medium]]></description>
        <link>https://medium.com/@srukshan98?source=rss-2fcc3a485dd0------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*gIqxSiI-r0ziNxGqaZWaDg.jpeg</url>
            <title>Stories by Sachith Rukshan on Medium</title>
            <link>https://medium.com/@srukshan98?source=rss-2fcc3a485dd0------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Wed, 02 Dec 2026 06:59:12 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@srukshan98/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[A Seamless Hot Reload with Dynamic Federation in Angular]]></title>
            <description><![CDATA[<div class="medium-feed-item"><p class="medium-feed-image"><a href="https://srukshan98.medium.com/achieving-seamless-hot-reload-with-dynamic-federation-in-angular-883f70066c67?source=rss-2fcc3a485dd0------2"><img src="https://cdn-images-1.medium.com/max/1536/1*Y2fVc6FnAVjyzg8sy5_gmw.png" width="1536"></a></p><p class="medium-feed-snippet">When working with Angular and Native Federation, especially in dynamic federation setups, one common pain point is the loss of hot reload&#x2026;</p><p class="medium-feed-link"><a href="https://srukshan98.medium.com/achieving-seamless-hot-reload-with-dynamic-federation-in-angular-883f70066c67?source=rss-2fcc3a485dd0------2">Continue reading on Medium »</a></p></div>]]></description>
            <link>https://srukshan98.medium.com/achieving-seamless-hot-reload-with-dynamic-federation-in-angular-883f70066c67?source=rss-2fcc3a485dd0------2</link>
            <guid isPermaLink="false">https://medium.com/p/883f70066c67</guid>
            <category><![CDATA[angular]]></category>
            <category><![CDATA[dynamic-federation]]></category>
            <category><![CDATA[hot-module-replacement]]></category>
            <category><![CDATA[micro-frontends]]></category>
            <category><![CDATA[websocket]]></category>
            <dc:creator><![CDATA[Sachith Rukshan]]></dc:creator>
            <pubDate>Tue, 15 Apr 2025 02:04:14 GMT</pubDate>
            <atom:updated>2025-04-15T04:20:22.428Z</atom:updated>
        </item>
        <item>
            <title><![CDATA[New Angular: Elevating Web Development with New Tools and Techniques]]></title>
            <link>https://srukshan98.medium.com/new-angular-elevating-web-development-with-new-tools-and-techniques-48537beb1f8b?source=rss-2fcc3a485dd0------2</link>
            <guid isPermaLink="false">https://medium.com/p/48537beb1f8b</guid>
            <category><![CDATA[angular-control-flow]]></category>
            <category><![CDATA[angular-signals]]></category>
            <category><![CDATA[ngzone]]></category>
            <category><![CDATA[angular]]></category>
            <dc:creator><![CDATA[Sachith Rukshan]]></dc:creator>
            <pubDate>Fri, 13 Oct 2023 02:15:15 GMT</pubDate>
            <atom:updated>2023-10-13T02:15:15.744Z</atom:updated>
            <content:encoded><![CDATA[<p>Angular, a favorite among developers, is always on the move, bringing fresh features with every update. The latest, Angular 17, stands out with its refined control flows and the introduction of ‘signals’. Let’s dive in!</p><h3>Control Flows: What’s New?</h3><p>If you’ve used Angular before, you’re familiar with directives like ngIf and ngFor. They help manage how content shows up on our web pages. Angular 17 offers a more straightforward way of doing this.</p><h4>Introducing the @if Control Flow</h4><p>Think of this as a direct way to show or hide parts of your web page:</p><pre>@if(isVisible()) {<br>  &lt;h1&gt;Welcome!&lt;/h1&gt;<br>}</pre><p>Here, the &lt;h1&gt; tag will only appear if the isVisible() signal function says it should.</p><h4>Meet the @for Control Flow</h4><p>This is a new way to loop through items and display them:</p><pre>@for (item of itemsList; track item.id) {<br>  &lt;p&gt;{{item.name}}&lt;/p&gt;<br>}</pre><p>It goes through each item in the itemsList and displays its name and uses track to identify when to re-render.</p><h3>Signals: Making Things React</h3><p>Angular has always been about reactions — how your page reacts when data changes. ‘Signals’ in Angular 16 and 17 make this even better. They’re like live wires, always ready to update the page when the data they’re connected to changes.</p><p>A quick example from our code:</p><pre>isShow: WritableSignal&lt;boolean&gt; = signal(false);<br>...<br>setInterval(()=&gt;{<br>  this.isShow.update((v) =&gt; !v);<br>}, 500);</pre><p>Here, the isShow signal keeps flipping between true and false every half-second. As you saw inside the new if condition it is just a call away.</p><h3>Manual Steering with ngZone: &#39;noop&#39;</h3><p>For those diving deeper, Angular usually auto-updates the page when data changes. But in our code, we’ve told Angular to let us handle it. This gives experts more control but means we need to tell Angular when to update, like this:</p><pre>this.cdr.detectChanges();</pre><h3>A Personal Dive into New Angular</h3><p>Having been a dedicated Angular developer for the past four years, I’ve witnessed its evolution firsthand. Every release has its charm, but Angular 17’s beta has genuinely stood out for me.</p><p>The introduction of the new @if and @for control flows felt like a reunion with native JavaScript, simplifying the template code and bridging the gap between JavaScript and Angular&#39;s template syntax. It&#39;s been a game-changer in terms of readability and efficiency.</p><p>Signals, for me, are the highlight of recent Angular innovations. Transitioning from traditional observables to signals has streamlined my reactive programming approach. The feature’s brilliance lies in its simplicity — removing the overhead of manual subscription management while enhancing performance.</p><p>Opting for manual control with ngZone: &#39;noop&#39; was an adventurous step. It offered a level of precision I hadn&#39;t tapped into before, proving invaluable in performance-critical scenarios. The responsibility of manually invoking change detection brought back memories of my early days with Angular, but with a matured perspective.</p><p>Reflecting on my journey, my love for Angular has only grown over the years. The framework’s adaptability and the community’s vibrancy have kept me hooked. Angular 17, with its promising features, reaffirms my commitment to this wonderful framework, and I eagerly await its stable release.</p><h3>Wrapping Up</h3><p>Whether you’re just starting with Angular or have been using it for years, Angular 17 is shaping up to be an exciting release. With more control over how our pages react and new, efficient ways to manage content, it’s a great time to be an Angular developer!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=48537beb1f8b" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Exploring Bun: A Delightful Runtime]]></title>
            <link>https://srukshan98.medium.com/exploring-bun-a-delightful-runtime-f9c074a13490?source=rss-2fcc3a485dd0------2</link>
            <guid isPermaLink="false">https://medium.com/p/f9c074a13490</guid>
            <category><![CDATA[qpress]]></category>
            <category><![CDATA[first-try]]></category>
            <category><![CDATA[js-runtime]]></category>
            <category><![CDATA[expressjs]]></category>
            <dc:creator><![CDATA[Sachith Rukshan]]></dc:creator>
            <pubDate>Fri, 15 Sep 2023 16:31:31 GMT</pubDate>
            <atom:updated>2023-09-15T16:31:31.844Z</atom:updated>
            <content:encoded><![CDATA[<h3>Introduction</h3><p>In the ever-evolving world of JavaScript development, finding tools and runtimes that boost productivity while maintaining performance is a constant quest. Recently, I stumbled upon Bun, a JavaScript runtime and toolkit designed for speed and developer convenience. In this article, I’ll share my journey with Bun, exploring its features, compatibility, and real-world use cases.</p><h3>What is Bun?</h3><p>Bun is a versatile JavaScript runtime and toolkit that promises speed and ease of use. It’s an all-in-one solution for developing, testing, running, and bundling JavaScript and TypeScript projects. With its native support for TypeScript, seamless Node.js compatibility, and a bundle of handy features, Bun aims to streamline the development workflow.</p><h3>Installation and Getting Started</h3><p>Getting started with Bun is a breeze(<a href="https://bun.sh/docs/installation">Goto install page</a>). By running a simple curl command, you can install Bun and have it up and running in no time. I was pleasantly surprised by how straightforward the installation process was, which set a positive tone for my exploration.</p><h3>SQLite Integration and File Access</h3><p>One of the aspects I was eager to test was Bun’s built-in SQLite support and file access implementations. In my experiments, Bun proved to be a capable performer, handling SQLite databases and file operations with finesse. It offered a seamless experience that felt in tune with the demands of modern web development.</p><p>In one of my tests with Bun, I experimented with integrating SQLite support. Here’s a code snippet that demonstrates how straightforward it is to work with Bun’s SQLite integration:</p><pre>// Importing Bun&#39;s SQLite module<br>import { Database } from &#39;bun:sqlite&#39;;<br>// Creating a new SQLite database<br>const db = new Database(&#39;sample.sqlite&#39;);<br>try {<br> // Attempting a query on the &#39;Customer&#39; table<br> db.query(&#39;SELECT 0 FROM Customer&#39;);<br>} catch (err) {<br> // If the table doesn&#39;t exist, initialize it from an &#39;init.data&#39; file<br> const init = await file(&#39;init.data&#39;).text();<br> db.run(init);<br>}<br>// Querying the &#39;Customer&#39; table and logging the results<br>console.log(db.query(&#39;SELECT * FROM Customer&#39;).all());<br>// Closing the database connection<br>db.close();<br>// Cleaning up by removing the database file<br>unlinkSync(&#39;sample.sqlite&#39;);</pre><h3>Node.js Compatibility</h3><p>One of Bun’s standout features is its promise to be a drop-in replacement for Node.js. To put this claim to the test, I integrated Bun with Express.js, a popular Node.js framework. The compatibility was impressive, allowing me to leverage existing Node.js packages and libraries without major modifications.</p><pre>// Integrating Bun with Express.js<br>const express = require(&#39;express&#39;);<br>const app = express();<br><br>// Creating a route with Express<br>app.get(&#39;/&#39;, (req, res) =&gt; {<br>    res.send(&#39;Hello, Bun and Express!&#39;);<br>});<br><br>// Starting the Express server<br>const port = 3000;<br>app.listen(port, () =&gt; {<br>    console.log(`Server is listening on port ${port}`);<br>});</pre><p>In this code snippet, I demonstrate how Bun can be seamlessly integrated with Express.js, showcasing its compatibility as a drop-in replacement for Node.js in server-side applications.</p><h3>TypeScript and Decorators</h3><p>For TypeScript enthusiasts like me, Bun’s support is a breath of fresh air. TypeScript integration was seamless, and what delighted me even more was how decorators “just worked.” The experience felt natural, and it significantly enhanced my development workflow.</p><pre>// TypeScript code with decorators in Bun<br>function testClassDec({ selector }: { selector: string }): (target: typeof Test, context: ClassDecoratorContext&lt;typeof Test&gt;) =&gt; void | typeof Test {<br>    return (target: typeof Test, context: ClassDecoratorContext&lt;typeof Test&gt;) =&gt; {<br>        console.log(&#39;Log: &#39;, selector, target, context);<br>    }<br>}<br><br>function Input(): (target: undefined, context: ClassFieldDecoratorContext&lt;Test, string&gt; &amp; { name: string; private: false; static: false; }) =&gt; void | ((this: Test, value: string) =&gt; string) {<br>    return (target: undefined, context: ClassFieldDecoratorContext&lt;Test, string&gt; &amp; { name: string; private: false; static: false; }) =&gt; {<br>        console.log(&#39;Log: &#39;, target, context);<br>    }<br>}<br><br>@testClassDec({<br>    selector: &#39;Testing&#39;<br>})<br>class Test {<br>    @Input() testIn!: string;<br>    @Input() testIn2!: string;<br>}</pre><p>This TypeScript code snippet showcases how Bun seamlessly supports TypeScript and decorators, enhancing the development experience with type-checking and decorators for metadata and functionality.</p><h3>Bundling with React (Stay tuned!)</h3><p>In my next experiment, I plan to dive into Bun’s capabilities as a bundler, particularly when working with React. I have high expectations for Bun in terms of performance and ease of use. Stay tuned for the results of this exciting test.</p><h3>Using Bun with qpress</h3><p>As a developer who has created my own framework named qpress ts(@qpress/core, @qpress/cli), I was curious to see how Bun would integrate with it. To my delight, Bun seamlessly worked alongside my framework, offering an efficient development experience.</p><p>This code block showcases how Bun can be integrated into your qpress ts framework. It initializes a qpress application, attaches modules, and starts the application.</p><pre>import { LogLevelType, qpress } from &#39;@qpress/core&#39;<br>import { AppModule } from &#39;./src/app.module&#39;;<br><br>console.time(&#39;App Initialization&#39;)<br>const app = qpress({<br>    LogLevel: LogLevelType.None,<br>    JsonParser: true,<br>    // SocketEnabled:true<br>});<br>console.timeEnd(&#39;App Initialization&#39;)<br><br>console.time(&#39;Attach Modules&#39;)<br>app.attachModule(AppModule);<br>console.timeEnd(&#39;Attach Modules&#39;)<br><br>app.runApp();</pre><h3>Conclusion</h3><p>Bun is shaping up to be a valuable addition to the JavaScript development landscape. Its commitment to speed, ease of use, and compatibility with existing tools and packages positions it as a promising choice for modern developers. What’s even more impressive is that it accomplishes all this as a version 1.0 release.</p><p>My journey with Bun has been a positive one so far, and I’m eager to explore more of its capabilities. As I continue testing Bun and pushing its boundaries, I can’t help but be excited about what lies ahead for this runtime and toolkit.</p><h3>Final Thoughts</h3><p>As the JavaScript ecosystem continues to evolve, tools like Bun demonstrate the potential to streamline our workflows and enhance our productivity. I encourage fellow developers to give Bun a try and share their experiences. Together, we can contribute to the growth and improvement of this exciting JavaScript runtime.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f9c074a13490" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Building a Dynamic Form Builder and Renderer Library in Angular — Part 3/3]]></title>
            <link>https://srukshan98.medium.com/building-a-dynamic-form-builder-and-renderer-library-in-angular-part-3-3-6ebdfb87abcb?source=rss-2fcc3a485dd0------2</link>
            <guid isPermaLink="false">https://medium.com/p/6ebdfb87abcb</guid>
            <dc:creator><![CDATA[Sachith Rukshan]]></dc:creator>
            <pubDate>Thu, 16 Mar 2023 08:13:59 GMT</pubDate>
            <atom:updated>2023-03-16T08:13:59.915Z</atom:updated>
            <content:encoded><![CDATA[<h3>Building a Dynamic Form Builder and Renderer Library in Angular — Part 3/3</h3><p>In the previous parts, we set up the Angular project, created the form builder library, built the form builder component, added custom text fields and layouts, and created a dialog for customizing form fields and text fields. In Part 3, we’ll cover:</p><ol><li>Emitting the form configuration</li><li>Implementing the form renderer component</li><li>Adding toJSON and fromJSON methods to the Layout class</li></ol><h3>Part 3</h3><h4>6. Emitting the form configuration:</h4><p>To emit the form configuration, create an output event in the form builder component:</p><pre>import { Output, EventEmitter } from &#39;@angular/core&#39;;<br><br>// Inside the FormBuilderComponent class<br>@Output() formConfigChange = new EventEmitter&lt;LayoutColumn[]&gt;();</pre><p>Update the drop() method and the openEditDialog() method to emit the form configuration when it&#39;s updated:</p><pre>drop(event: CdkDragDrop&lt;DraggableItem[] | LayoutColumn[]&gt;) {<br>  // ...existing code<br>  this.formConfigChange.emit(this.layout);<br>}<br><br>openEditDialog(item: DraggableItem): void {<br>  // ...existing code<br>  dialogRef.afterClosed().subscribe((result: DraggableItem) =&gt; {<br>    if (result) {<br>      // ...existing code<br>      this.formConfigChange.emit(this.layout);<br>    }<br>  });<br>}</pre><h4>7. Implementing the form renderer component:</h4><p>Generate a new form renderer component in the library:</p><pre>ng generate component form-renderer --project=form-builder</pre><p>Implement the form renderer component to render the final form based on the configuration generated by the form builder. In form-renderer.component.ts, create an input property for the form configuration:</p><pre>import { Input } from &#39;@angular/core&#39;;<br><br>// Inside the FormRendererComponent class<br>@Input() layout: LayoutColumn[];</pre><p>In form-renderer.component.html, use the layout input property to render the form fields, headings, and paragraphs:</p><pre>&lt;div *ngFor=&quot;let column of layout&quot;&gt;<br>  &lt;ng-container *ngFor=&quot;let item of column.items&quot;&gt;<br>    &lt;ng-container [ngSwitch]=&quot;item.type&quot;&gt;<br>      &lt;ng-container *ngSwitchCase=&quot;&#39;form-field&#39;&quot;&gt;<br>        &lt;input [attr.type]=&quot;item.content.type&quot; [attr.placeholder]=&quot;item.content.label&quot; /&gt;<br>      &lt;/ng-container&gt;<br>      &lt;ng-container *ngSwitchCase=&quot;&#39;heading&#39;&quot;&gt;<br>        &lt;h3&gt;{{item.content}}&lt;/h3&gt;<br>      &lt;/ng-container&gt;<br>      &lt;ng-container *ngSwitchCase=&quot;&#39;paragraph&#39;&quot;&gt;<br>        &lt;p&gt;{{item.content}}&lt;/p&gt;<br>      &lt;/ng-container&gt;<br>    &lt;/ng-container&gt;<br>  &lt;/ng-container&gt;<br>&lt;/div&gt;</pre><h4>8. Adding toJSON and fromJSON methods to the Layout class:</h4><p>Update the LayoutColumn interface to include toJSON and fromJSON methods:</p><pre>export interface LayoutColumn {<br>  items: DraggableItem[];<br>  toJSON(): any;<br>  fromJSON(json: any): LayoutColumn;<br>}</pre><p>Implement the toJSON and fromJSON methods in the LayoutColumn class. These methods will allow the form configuration to be easily serialized and deserialized between JSON and Layout instances:</p><pre>export class LayoutColumn {<br>  constructor(public items: DraggableItem[]) {}<br>  toJSON(): any {<br>    return {<br>      items: this.items.map(item =&gt; {<br>        return {<br>          id: item.id,<br>          type: item.type,<br>          content: item.content,<br>        };<br>      }),<br>    };<br>  }<br>  fromJSON(json: any): LayoutColumn {<br>    this.items = json.items.map((item: any) =&gt; ({<br>      id: item.id,<br>      type: item.type,<br>      content: item.content,<br>    }));<br>    return this;<br>  } <br>}</pre><p>Now, the form builder can emit the form configuration as a JSON object, which can be saved, shared, or stored as needed. The form renderer component can take this JSON object as an input and render the form accordingly. To use the form builder and renderer components in your Angular application, import the `FormBuilderModule` and use the `lib-form-builder` and `lib-form-renderer` components:</p><pre>&lt;lib-form-builder (formConfigChange)=&quot;onFormConfigChange($event)&quot;&gt;&lt;/lib-form-builder&gt;<br>&lt;lib-form-renderer [layout]=&quot;formLayout&quot;&gt;&lt;/lib-form-renderer&gt;</pre><p>In your component TypeScript file, implement the onFormConfigChange method to handle the form configuration changes:</p><pre>formLayout: LayoutColumn[];<br><br>onFormConfigChange(layout: LayoutColumn[]): void {<br>  this.formLayout = layout;<br>}</pre><p>That’s it! You’ve now built a dynamic form builder and renderer library in Angular. This library allows users to create custom forms using a drag-and-drop interface and render them based on the generated configuration. With the provided customization options, users can create forms with various form fields, headings, paragraphs, and layouts to meet their specific needs.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6ebdfb87abcb" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Building a Dynamic Form Builder and Renderer Library in Angular — Part 2/3]]></title>
            <link>https://srukshan98.medium.com/building-a-dynamic-form-builder-and-renderer-library-in-angular-part-2-3-2853456db3ab?source=rss-2fcc3a485dd0------2</link>
            <guid isPermaLink="false">https://medium.com/p/2853456db3ab</guid>
            <dc:creator><![CDATA[Sachith Rukshan]]></dc:creator>
            <pubDate>Thu, 16 Mar 2023 07:40:27 GMT</pubDate>
            <atom:updated>2023-03-16T08:15:24.166Z</atom:updated>
            <content:encoded><![CDATA[<h3>Building a Dynamic Form Builder and Renderer Library in Angular — Part 2/3</h3><p>In the previous part, we set up the Angular project, created the form builder library, and built the form builder component. In Part 2, we’ll cover:</p><ol><li>Adding custom text fields and layouts</li><li>Creating a dialog for customizing form fields and text fields</li></ol><h3>Part 2</h3><h4>4. Adding custom text fields and layouts:</h4><p>To add custom text fields (headings and paragraphs) and support different layouts (rows with varying numbers of columns), we’ll update the LayoutColumn and DraggableItem models and implement the drag-and-drop functionality for these fields.</p><p>First, update the DraggableItem model in form-builder.component.ts to support custom text fields:</p><pre>export interface DraggableItem {<br>  id: string;<br>  type: &#39;form-field&#39; | &#39;heading&#39; | &#39;paragraph&#39;;<br>  content: FormField | string;<br>}</pre><p>Extend the availableFormFields array to include headings and paragraphs:</p><pre>availableFormFields: DraggableItem[] = [<br>  // ...existing form fields<br>  { id: &#39;5&#39;, type: &#39;heading&#39;, content: &#39;Heading&#39; },<br>  { id: &#39;6&#39;, type: &#39;paragraph&#39;, content: &#39;Paragraph&#39; },<br>];</pre><p>Update the form-builder.component.html template to display headings and paragraphs:</p><pre>&lt;mat-card *ngFor=&quot;let item of layout[0].items&quot; cdkDrag&gt;<br>  &lt;ng-container [ngSwitch]=&quot;item.type&quot;&gt;<br>    &lt;ng-container *ngSwitchCase=&quot;&#39;form-field&#39;&quot;&gt;{{item.content.label}}&lt;/ng-container&gt;<br>    &lt;ng-container *ngSwitchCase=&quot;&#39;heading&#39;&quot;&gt;<br>      &lt;h3&gt;{{item.content}}&lt;/h3&gt;<br>    &lt;/ng-container&gt;<br>    &lt;ng-container *ngSwitchCase=&quot;&#39;paragraph&#39;&quot;&gt;<br>      &lt;p&gt;{{item.content}}&lt;/p&gt;<br>    &lt;/ng-container&gt;<br>  &lt;/ng-container&gt;<br>&lt;/mat-card&gt;</pre><h4>5. Creating a dialog for customizing form fields and text fields:</h4><p>Generate a new component for the edit dialog:</p><pre>ng generate component form-builder/edit-dialog --project=form-builder</pre><p>Use Angular Material to create a simple form for editing the properties of form fields and text fields. In edit-dialog.component.html, add the following:</p><pre>&lt;h1 mat-dialog-title&gt;Edit Item&lt;/h1&gt;<br>&lt;div mat-dialog-content&gt;<br>  &lt;mat-form-field appearance=&quot;fill&quot;&gt;<br>    &lt;mat-label *ngIf=&quot;data.type === &#39;form-field&#39;&quot;&gt;Label&lt;/mat-label&gt;<br>    &lt;input matInput [(ngModel)]=&quot;data.content.label&quot; *ngIf=&quot;data.type === &#39;form-field&#39;&quot; /&gt;<br>  &lt;/mat-form-field&gt;<br>  &lt;mat-form-field appearance=&quot;fill&quot; *ngIf=&quot;data.type === &#39;heading&#39; || data.type === &#39;paragraph&#39;&quot;&gt;<br>    &lt;mat-label&gt;Text&lt;/mat-label&gt;<br>    &lt;input matInput [(ngModel)]=&quot;data.content&quot; /&gt;<br>  &lt;/mat-form-field&gt;<br>&lt;/div&gt;<br>&lt;div mat-dialog-actions&gt;<br>  &lt;button mat-button mat-dialog-close&gt;Cancel&lt;/button&gt;<br>  &lt;button mat-button [mat-dialog-close]=&quot;data&quot;&gt;Save&lt;/button&gt;<br>&lt;/div&gt;</pre><p>In edit-dialog.component.ts, import MAT_DIALOG_DATA and MatDialogRef from Angular Material and update the constructor to inject the dialog data:</p><pre>import { Component, Inject } from &#39;@angular/core&#39;;<br>import { MatDialogRef, MAT_DIALOG_DATA } from &#39;@angular/material/dialog&#39;;<br><br>@Component({<br>  selector: &#39;lib-edit-dialog&#39;,<br>  templateUrl: &#39;./edit-dialog.component.html&#39;,<br>  styleUrls: [&#39;./edit-dialog.component.scss&#39;]<br>})<br>export class EditDialogComponent {<br>  constructor(<br>    public dialogRef: MatDialogRef&lt;EditDialogComponent&gt;, <br>    @Inject(MAT_DIALOG_DATA) public data: DraggableItem<br>  ) {}<br>}</pre><p>Now, integrate the dialog into the form builder component. In `form-builder.component.ts`, import `MatDialog` and create a method to open the edit dialog:</p><pre>import { MatDialog } from &#39;@angular/material/dialog&#39;;<br>import { EditDialogComponent } from &#39;./edit-dialog/edit-dialog.component&#39;;</pre><pre>// Inside the FormBuilderComponent class<br>constructor(private dialog: MatDialog) {}</pre><pre>openEditDialog(item: DraggableItem): void {<br>  const dialogRef = this.dialog.open(EditDialogComponent, {<br>    width: &#39;300px&#39;,<br>    data: JSON.parse(JSON.stringify(item)),<br>  });</pre><pre>  dialogRef.afterClosed().subscribe((result: DraggableItem) =&gt; {<br>    if (result) {<br>      const itemIndex = this.layout[0].items.findIndex(i =&gt; i.id === result.id);<br>      this.layout[0].items[itemIndex] = result;<br>    }<br>  });<br>}</pre><p>Finally, update the form-builder.component.html template to include the openEditDialog() method when an item is clicked:</p><pre>&lt;mat-card<br>  *ngFor=&quot;let item of layout[0].items&quot;<br>  cdkDrag<br>  (click)=&quot;openEditDialog(item)&quot;<br>&gt;<br>  &lt;!-- Existing content --&gt;<br>&lt;/mat-card&gt;</pre><p>In <a href="https://srukshan98.medium.com/building-a-dynamic-form-builder-and-renderer-library-in-angular-part-3-3-6ebdfb87abcb">Part 3</a>, we will cover:</p><ol><li>Emitting the form configuration</li><li>Implementing the form renderer component</li><li>Adding toJSON and fromJSON methods to the Layout class</li></ol><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2853456db3ab" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Building a Dynamic Form Builder and Renderer Library in Angular — Part 1/3]]></title>
            <link>https://srukshan98.medium.com/building-a-dynamic-form-builder-and-renderer-library-in-angular-part-1-3-471eda8ce11c?source=rss-2fcc3a485dd0------2</link>
            <guid isPermaLink="false">https://medium.com/p/471eda8ce11c</guid>
            <category><![CDATA[formbuilder]]></category>
            <category><![CDATA[angular]]></category>
            <dc:creator><![CDATA[Sachith Rukshan]]></dc:creator>
            <pubDate>Thu, 16 Mar 2023 05:38:12 GMT</pubDate>
            <atom:updated>2023-03-16T08:14:59.761Z</atom:updated>
            <content:encoded><![CDATA[<h3>Building a Dynamic Form Builder and Renderer Library in Angular — Part 1/3</h3><p>Introduction:</p><p>In this three-part tutorial, we’ll guide you through creating a form builder and renderer library in Angular. The library will enable users to create custom forms with various form fields, headings, and paragraphs using a drag-and-drop interface. The form renderer will take the configuration generated by the form builder and display the final form to the user.</p><p>Part 1 will cover:</p><ol><li>Setting up the Angular project</li><li>Creating the form builder library</li><li>Building the form builder component</li></ol><h3>Part 1</h3><h4>1. Setting up the Angular project:</h4><p>First, create a new Angular project using the Angular CLI:</p><pre>ng new form-builder-demo --style=scss<br>cd form-builder-demo</pre><p>Install the Angular Material and Angular CDK libraries:</p><pre>ng add @angular/material</pre><h4>2. Creating the form builder library:</h4><p>Generate a new library called “form-builder”:</p><pre>ng generate library form-builder</pre><h4>3. Building the form builder component:</h4><p>Create the form builder component in the library using the Angular CLI:</p><pre>ng generate component form-builder --project=form-builder</pre><p>In form-builder.component.ts, import the necessary modules from Angular CDK:</p><pre>import { CdkDragDrop, moveItemInArray, transferArrayItem } from &#39;@angular/cdk/drag-drop&#39;;</pre><p>Define the layout model, form field model, and draggable item model:</p><pre>export interface FormField {<br>  id: string;<br>  label: string;<br>  type: string;<br>}<br>export interface DraggableItem {<br>  id: string;<br>  type: string;<br>  content: FormField | string;<br>}<br>export interface LayoutColumn {<br>  items: DraggableItem[];<br>}</pre><p>Implement the drag-and-drop interface by creating an array of available form fields and an array representing the layout. Implement the drop() method to handle the drag-and-drop events.</p><pre>export class FormBuilderComponent {<br>  availableFormFields: DraggableItem[] = [<br>    { id: &#39;1&#39;, type: &#39;input&#39;, content: { id: &#39;1&#39;, label: &#39;Text Input&#39;, type: &#39;text&#39; } },<br>    // Other form fields<br>  ];<br>  layout: LayoutColumn[] = [<br>    { items: [] },<br>  ];<br>  drop(event: CdkDragDrop&lt;DraggableItem[] | LayoutColumn[]&gt;) {<br>    if (event.previousContainer === event.container) {<br>      moveItemInArray(event.container.data, event.previousIndex, event.currentIndex);<br>    } else {<br>      const itemCopy = JSON.parse(JSON.stringify(event.previousContainer.data[event.previousIndex]));<br>      transferArrayItem(event.previousContainer.data,<br>                        event.container.data,<br>                        event.previousIndex,<br>                        event.currentIndex,<br>                        itemCopy);<br>    }<br>  }<br>}</pre><p>In form-builder.component.html, create the drag-and-drop interface using Angular Material components and Angular CDK directives:</p><pre>&lt;div cdkDropList [cdkDropListData]=&quot;availableFormFields&quot; class=&quot;form-field-list&quot;&gt;<br>  &lt;mat-card *ngFor=&quot;let field of availableFormFields&quot; cdkDrag&gt;<br>    {{field.content.label}}<br>  &lt;/mat-card&gt;<br>&lt;/div&gt;</pre><p>In <a href="https://srukshan98.medium.com/building-a-dynamic-form-builder-and-renderer-library-in-angular-part-2-3-2853456db3ab">Part 2</a>, we will cover:</p><ol><li>Adding custom text fields and layouts</li><li>Creating a dialog for customizing form fields and text fields</li></ol><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=471eda8ce11c" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>