<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: preetha S S</title>
    <description>The latest articles on DEV Community by preetha S S (@preetha_ss_8da7339634285).</description>
    <link>https://dev.to/preetha_ss_8da7339634285</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F3935268%2F828aea5a-86e8-4b60-92b8-7aadf5823bee.png</url>
      <title>DEV Community: preetha S S</title>
      <link>https://dev.to/preetha_ss_8da7339634285</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/preetha_ss_8da7339634285"/>
    <language>en</language>
    <item>
      <title>ANGULAR DYNAMIC FORMS</title>
      <dc:creator>preetha S S</dc:creator>
      <pubDate>Sat, 16 May 2026 18:03:39 +0000</pubDate>
      <link>https://dev.to/preetha_ss_8da7339634285/angular-dynamic-forms-o3o</link>
      <guid>https://dev.to/preetha_ss_8da7339634285/angular-dynamic-forms-o3o</guid>
      <description>&lt;p&gt;&lt;strong&gt;What is dynamic forms in angular ?&lt;/strong&gt;- The most asked interview question &lt;/p&gt;

&lt;p&gt;In simple terms, dynamic forms mean that the form field configuration comes from the backend as a JSON response. On the frontend, we simply read this configuration and render the form dynamically with minimal code.&lt;br&gt;
Lets see how we can achieve this &lt;/p&gt;

&lt;p&gt;First let me clarify Reactive forms include static form field declaration which means you will need to declare each field and use the same in fromGroup but here as the fields come from JSON you just need to dynamically handle the fields in formGroup.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;&lt;u&gt;.ts file&lt;/u&gt;&lt;/em&gt;&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="s2"&gt;`export class DynamicFormComponent implements OnInit {

  form!: FormGroup;
//json from BE
  fields = [
    { type: 'text', name: 'firstName', label: 'First Name', required: true },
    { type: 'email', name: 'email', label: 'Email', required: true },
    { type: 'number', name: 'age', label: 'Age', required: false }
  ];

  constructor(private fb: FormBuilder) {}

  ngOnInit() {
    const group: any = {};

    this.fields.forEach(field =&amp;gt; {
      group[field.name] = field.required
        ? ['', Validators.required]
        : [''];
    });

    this.form = this.fb.group(group);
  }`&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;&lt;em&gt;&lt;u&gt;.html file&lt;/u&gt;&lt;/em&gt;&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;`  &lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;*ngFor=&lt;/span&gt;&lt;span class="s"&gt;"let field of fields"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;label&amp;gt;&lt;/span&gt;{{ field.label }}&lt;span class="nt"&gt;&amp;lt;/label&amp;gt;&lt;/span&gt;

    &lt;span class="nt"&gt;&amp;lt;input&lt;/span&gt;
      &lt;span class="na"&gt;[type]=&lt;/span&gt;&lt;span class="s"&gt;"field.type"&lt;/span&gt;
      &lt;span class="na"&gt;[formControlName]=&lt;/span&gt;&lt;span class="s"&gt;"field.name"&lt;/span&gt;
    &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;

    &lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;*ngIf=&lt;/span&gt;&lt;span class="s"&gt;"form.get(field.name)?.invalid &amp;amp;&amp;amp; form.get(field.name)?.touched"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
      {{ field.label }} is required
    &lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;`&lt;/p&gt;

</description>
      <category>angular</category>
      <category>tutorial</category>
      <category>typescript</category>
      <category>webdev</category>
    </item>
  </channel>
</rss>
