角动态表单验证

时间:2019-05-07 12:08:32

标签: angular forms dynamic

在json的Angular动态中,是这样的

regConfig: FieldConfig[] = [
   {
     type: "input",
     label: "Username",
     inputType: "text",
     name: "name",
     validations: [
       {
         name: "required",
         validator: Validators.required,
         message: "Name Required"
       },
       {
         name: "pattern",
         validator: Validators.pattern("^[a-zA-Z]+$"),
         message: "Accept only text"
       }
     ]
   }

可以很好地进行验证

但是我们正在从后端像这样从json发送响应

regConfig: FieldConfig[] = [
   {
     type: "input",
     label: "Username",
     inputType: "text",
     name: "name",
     validations: [
       {
         name: "required",
         validator: "Validators.required",
         message: "Name Required"
       },
       {
         name: "pattern",
         validator: Validators.pattern("^[a-zA-Z]+$"),
         message: "Accept only text"
       }
     ]
   }

请参阅验证器属性。 所以我的问题是:

有没有办法像这样的验证器从后端RestController发送数据?

或者我们可以像下面这样的验证器来动态处理值:“ Validators.required”

我正在遵循这种示例

https://github.com/bahurudeen/dynamicform

0 个答案:

没有答案