angular-schematics - 将集合传递到自定义角度示意图?
问题描述
我想创建一个可以接受一组动作名称的自定义角度示意图。然后,我将为用户提供的每个操作名称生成 3 个 ngrx 操作。
例如,我想创建一个可以像这样调用的原理图:
ng g my-collection:my-schematic --actions=GetById,GetByFirstName
然后,我将为 GetById、GetByIdSuccess、GetByIdError、GetByFirstName、GetByFirstNameSuccess、GetByFirstNameError 生成代码。
问题是我只看到了将接受单个值作为输入参数的角度示意图。任何人都知道如何在自定义角度示意图中处理集合?
解决方案
如果您想直接从命令 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
如果您不提供任何参数,架构中的值不会导致原理图失败。您需要在原理图中对该属性进行验证。
推荐阅读
- javascript - Syncfusion Vuejs 数据透视表
- r - 将 000 转换为 K
- java - 如何从 viewHolder 中的 Asynctask 获取结果?
- java - 从对象列表中获取最大值
- angular - 角度测试 - 表单输入 type="number" 应该只接受数字
- python - 尝试通过 key 从 request.form 获取值时出现 exceptions.badrequestkeyerror(key)
- php - Laravel 6 - 控制器中的更新功能运行但模型未传递给控制器
- asp.net - ASP.NET 突然想要一个斜杠
- mongodb - 如何在猫鼬中检查日期是否小于今天的日期?
- eclipse - Log4J2 - 从 Eclipse 运行时不发生日志记录