指令 — 字段渲染 / 字段绑定等
本文介绍 @piying/view-angular 提供的指令:InsertFieldDirective、PiyingFieldTemplateDirective、PiyingFieldControlBindDirective、AttributesDirective / EventsDirective。
⚠️ 这里是指库内置暴露给用户的指令。若你关心如何通过
actions.directives把自定义指令附加到字段,请见 字段指令配置。
InsertFieldDirective
Section titled “InsertFieldDirective”Wrapper 的字段插入点指令,selector: '[insertField]',exportAs: 'insertField',继承 PiyingCreateComponentBase。在 Wrapper 模板中声明插入位置:
输入:
| 输入 | 类型 | 说明 |
|---|---|---|
insertFieldSlots |
Record<string, TemplateRef> |
传入的插槽模板,会合并进字段 slots |
insertFieldAttributes |
Record<string, any> |
传入的属性,会合并进字段 inputs |
PiyingFieldTemplateDirective
Section titled “PiyingFieldTemplateDirective”渲染字段的指令,selector: '[fieldTemplate]',standalone,exportAs: 'fieldTemplate',继承 DynamicCreateDirective:
| 输入 | 类型 | 说明 |
|---|---|---|
fieldTemplate |
PiResolvedViewFieldConfig(必填) |
要渲染的字段配置 |
path |
KeyPath(可选) |
通过路径定位子字段 |
onInit |
(field) => void(可选) |
字段首次初始化时执行一次的回调 |
field$$ 根据 path 计算:有 path 时取 fieldTemplate().get(keyPath),否则取 fieldTemplate()。
onInit
Section titled “onInit”onInit 在字段首次完成解析并生成时执行一次,之后字段更新不会再触发(内部以 #initialized 标记保证只调用一次):
同时提供 summaryList$$ / valibotIssueSummary$$ 用于错误摘要(基于 errorSummary)。
PiyingFieldControlBindDirective
Section titled “PiyingFieldControlBindDirective”将字段绑定为表单控件(NgControl),selector: '[formControl]',standalone,exportAs: 'formControl',继承 FieldControlBase。可在自定义模板中手动绑定字段:
输入:
| 输入 | 类型 | 说明 |
|---|---|---|
formControl |
_PiResolvedCommonViewFieldConfig(必填) |
要绑定的字段配置 |
path |
KeyPath(可选) |
通过路径定位子字段 |
fieldControl$$ 校验:若目标不是叶子控件会抛错 🏷️ fieldControl❗。它通过 formControlBinding Provider 提供 NgControl,模拟动态绑定。
AttributesDirective / EventsDirective
Section titled “AttributesDirective / EventsDirective”内部指令,standalone,分别将 actions.attributes / actions.events 绑定到组件 DOM:
AttributesDirective:selector: '[attributes]',输入attributes(必填)、excludes(排除的属性键)。变更时用Renderer2.setAttribute设置、移除已删除属性。EventsDirective:selector: '[events]',输入events(必填,Record<string, (event) => any>)。变更时重新监听事件,销毁时解绑。
- 组件 — PiyingView / PiyingViewGroup
- Angular API 参考 — 全部公开 API 索引
- PiyingFieldTemplate(字段渲染) — 跨框架的统一渲染管线
- PiyingField(字段绑定) — 跨框架的统一字段绑定语义
- 适配器总览 — 适配器分层与渲染链路