首页 > 解决方案 > 将集合传递到自定义角度示意图?

问题描述

我想创建一个可以接受一组动作名称的自定义角度示意图。然后,我将为用户提供的每个操作名称生成 3 个 ngrx 操作。

例如,我想创建一个可以像这样调用的原理图:

ng g my-collection:my-schematic --actions=GetById,GetByFirstName

然后,我将为 GetById、GetByIdSuccess、GetByIdError、GetByFirstName、GetByFirstNameSuccess、GetByFirstNameError 生成代码。

问题是我只看到了将接受单个值作为输入参数的角度示意图。任何人都知道如何在自定义角度示意图中处理集合?

标签: angular-schematics

解决方案


如果您想直接从命令 args 中提取它们,您可以执行以下操作:

{
  "$schema": "http://json-schema.org/draft-07/schema",
  "$id": "Sample",
  "title": "Sample Schematic",
  "type": "object",
  "description": "Does stuff.",
  "additionalProperties": false,
  "properties": {
    "things": {
      "type": "array",
      "items": {
        "type": "string"
      },
      "$default": {
        "$source": "argv"
      },
      "description": "Things from the command-line args."
    }
  }
}

然后,当您运行原理图时,您可以执行以下操作:

schematics schematic-lib:sample stuff other-stuff more-stuff

在这种情况下,things属性将为['stuff', 'other-stuff', 'more-stuff']

编辑:请注意,required如果您不提供任何参数,架构中的值不会导致原理图失败。您需要在原理图中对该属性进行验证。


推荐阅读