如何使用属性文件配置表单字段是否需要验证?

时间:2019-05-06 02:21:34

标签: angular angular-forms

如何配置表单字段是否需要验证或是否不使用属性文件。

例如:我们有很多表单字段。姓名,年龄,地址

使用配置文件需要输入名称和年龄。

以后如果需要将“年龄”设为可选。

我们如何将其存档。

1 个答案:

答案 0 :(得分:1)

您可以通过npm i angular6-json-schema-form安装软件包angular6-json-schema-form

在ts文件中以json格式配置表单

exampleJsonObject = {
  "first_name": "Jane", "last_name": "Doe", "age": 25, "is_company": false,
  "address": {
    "street_1": "123 Main St.", "street_2": null,
    "city": "Las Vegas", "state": "NV", "zip_code": "89123"
  },
  "phone_numbers": [
    { "number": "702-123-4567", "type": "cell" },
    { "number": "702-987-6543", "type": "work" }
  ], "notes": ""
};

在HTML

<json-schema-form
  loadExternalAssets="true"
  [(ngModel)]="exampleJsonObject">
</json-schema-form>

更多参考

包裹https://www.npmjs.com/package/angular6-json-schema-form

示例https://hamidihamza.com/Angular6-json-schema-form/

相关问题