title: How to write a validator for dynamic form in angular?
body: <p>I'm using angular 8 and I wrote a dynamic form. I want to write a validator mapper form  to validate my form controles but it doesn't work correctly.</p>
  <p><strong>ts</strong></p>
  <pre><code>       for (const prop of this.formConfig) {
      
            this.form.addControl(
              prop.id, new FormControl(
                prop.value,
              this.mapValidator(prop.validations)
              )
            )
            }
  
  
    mapValidator(validators) {
      if (validators) {
           validators.forEach(validator=&gt;{
        if (validator.type=='required') {
  
          return [Validators.required];
        }})
      } else {
        return [];
      }
    }
  </code></pre>
  <p><strong>config</strong></p>
  <pre><code>&quot;formConfig&quot;: [
    {
      &quot;name&quot;: &quot;firstName&quot;,
      &quot;label&quot;: &quot;name &quot;,
       &quot;value&quot; : &quot;&quot;,
       &quot;id&quot; : &quot;1&quot;
      &quot;type&quot;: &quot;text&quot;,
      &quot;validations&quot;: [
        {
          &quot;type&quot;: &quot;required&quot;
        }
      ]
    }
  </code></pre>