custom 自定义

custom 自定义

定制当前动态表单小部件。更复杂请参考定制小部件。

如何使用

务必指定 sf-template 是有效路径值,例如:

<​sf>  <​ng-template sf-template="custom" let-me let-ui="ui" let-schema="schema">  <​/ng-tempalte><​/sf>

代码演示

基础样例

最简单的用法。

import { Component } from '@angular/core';import { NzMessageService } from 'ng-zorro-antd/message';import { SFSchema } from '@delon/form';@Component({  selector: 'form-custom-simple',  template: `    <​sf [schema]="schema" (formSubmit)="submit($event)">      <​ng-template sf-template="custom" let-me let-ui="ui" let-schema="schema">        自定义内容:        <​input          nz-input          [attr.id]="me.id"          [disabled]="me.disabled"          [attr.disabled]="me.disabled"          [nzSize]="ui.size"          [ngModel]="me.formProperty.value"          (ngModelChange)="me.setValue($event)"        />      <​/ng-template>    <​/sf>  `,})export class FormCustomSimpleComponent {  schema: SFSchema = {    properties: {      custom: {        type: 'string',        title: '自定义内容',        ui: {          widget: 'custom',        },        default: 'test',      },    },  };  constructor(public msg: NzMessageService) {}  submit(value: any) {    this.msg.success(JSON.stringify(value));  }}

API

参数 说明 类型
[$implicit] 当前上下文 ControlWidget
[schema] 当前节点 Schema SFSchema
[ui] 当前节点 UI SFUISchemaItem

上下文包括 formProperty 属性,它是传递数据的唯一中间层,因此维护 formProperty.value 是唯一与自定义组件通信的媒介。

上下文还包含了一些快捷属性和方法,有关更多细节请阅读 Widget 的定义。