KA冉KA 2022-01-04 16:27 采纳率: 34.4%
浏览 25
已结题

angular + ng-zorro中form的日期时间控件

form中只有date和time的控件类型,没有日期时间(datetime)的控件类型:
.
.
.
this.register('number', NumberWidget); // 数值
this.register('date', DateWidget); // 日期
this.register('time', TimeWidget); // 时间
this.register('custom', CustomWidget); // 自定义

目前的使用写法:
this.register({name: '数字控件', type: 'number', options: [
{title: '控件配置', config: {...formConfig, schema: controlBaseOption}},
{title: '验证规则', config: {...formConfig, schema: controlBaseOption}},
]
});
.
.
.

想要其他控件类型,是否需要使用自定义,如何使用这个自定义的写法呢

  • 写回答

2条回答 默认 最新

  • 来回三五七 2022-01-05 09:49
    关注
    // html  方法可忽略
    <ng-template #finishTimeExpected let-data="data">
      <nz-date-picker
        nzShowTime
        [(ngModel)]="finishTimeExpectedTime"
        nzPlaceHolder=""
        (ngModelChange)="finishTimeOnChange($event, 'finishTimeExpected')"
      ></nz-date-picker>
    </ng-template>
    
    // ts
    @ViewChild('finishTimeExpected') finishTimeExpected: TemplateRef<HTMLDocument>;
    
    /**
       * 初始化表单配置
       */
      initColumn(): void {
        this.column = [
          {
            label: '时间',
            key: 'finishTimeExpected',
            type: 'custom', // 类型 自定义
            template: this.finishTimeExpected, // 自定义的模板
            rule: [{required: true}], // 规则
          }];
    }
    把写好的完整的表单配置传值给form:
    /**
       * 初始化表单配置
       */
      private initForm(): void {
        this.formGroup = new FormGroup({});
    // column 完整表单配置
    // language 语言包可忽略
        this.formOperate = new FormOperate(this.formGroup, this.column, this.language);
        this.column.forEach((item: FormItem) => {
          const value = item.initialValue || null; // 初始值可忽略
          const formControl = new FormControl({value: value, disabled: this.isDisabled || item.disabled},// 自定义规则可忽略
            this.formOperate.addRule(item.rule, item.customRules),// 自定义规则可忽略
            this.formOperate.addAsyncRule(item.asyncRules));// 自定义规则可忽略
          this.formGroup.addControl(item.key, formControl);// 自定义组件
        });
        this.formInstance.emit({instance: this.formOperate}); // 回传给页面渲染可忽略
      }
    
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论 编辑记录
查看更多回答(1条)

报告相同问题?

问题事件

  • 系统已结题 1月22日
  • 已采纳回答 1月14日
  • 创建了问题 1月4日

悬赏问题

  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘
  • ¥15 perl MISA分析p3_in脚本出错
  • ¥15 k8s部署jupyterlab,jupyterlab保存不了文件
  • ¥15 ubuntu虚拟机打包apk错误
  • ¥199 rust编程架构设计的方案 有偿
  • ¥15 回答4f系统的像差计算
  • ¥15 java如何提取出pdf里的文字?