如何通过引用字段模型向 NGX-Formly 添加自定义包装器?

How can I add a custom wrapper to NGX-Formly with references the field model?

我正在尝试为 NGX-Formly 字段实现一个包装器,该包装器具有一个按钮,该按钮调用一个处理函数来传递对包装字段模型的引用。如何注入此引用并将其传递给处理函数(例如打开弹出窗口或类似窗口)?

我的 objective 是创建一个拖放表单生成器。

根据 this example 我已经实现了这样的包装器:

<div class="formly-wrapper">
 <label>{{ to.label }}</label>
  <button (click)="myHandlerFunction()">Edit</button>
  <ng-container #fieldComponent></ng-container>
</div>

如何获取字段定义或至少对包装字段的引用?

经过反复尝试,我发现您可以像这样在包装器中传递 field

<button (click)="myHandlerFunction(field)">Edit</button>

这为您提供了完整的 FieldConfig,而 to 只是 TemplateOptions 的别名。