未在ngx-formly / bootstrap中显示自定义日期选择器的标签

问题描述 投票:0回答:1

我正在使用ngx-formly / bootstrap(不使用素材)创建动态UI /表单。我想显示datepicker控件,所以我使用ngx-bootstrap / datepicker显示了custon bsdatepicker控件。但是,当我在templateOptions中将其提供给标签时,标签未显示

我尝试了以下方式1.创建一个包含html用于日期选择器的组件

       import { BsDatepickerModule } from 'ngx-bootstrap/datepicker';
       //datepicker.component.html
       <input type="text" 
       id="dob-id" 
       class="form-control calendar" 
       placement="bottom" 
       bsDatepicker
       [formlyAttributes]="field"
       #dobDate="bsDatepicker" 
       [bsConfig]="bsConfig" 
       placeholder="YYYY-MM-DD"
       [class.is-invalid]="showError" class="wk-field-input"  style="width: 350px;">

       //datepicker.component.ts
       import { Component, OnInit } from '@angular/core';
       import { FieldType } from '@ngx-formly/core';
       import { BsDatepickerConfig } from 'ngx-bootstrap';

       @Component({
       selector: 'app-datepicker',
       templateUrl: './datepicker.component.html',
      styleUrls: ['./datepicker.component.scss']
      })

      export class CustomDatepickerComponent extends FieldType {
     // Optional: only if you want to rely on `MatInput` implementation
     bsConfig: Partial<BsDatepickerConfig> = {
     : 'YYYY-MM-DD',
     showWeekNumbers: false,
     containerClass: 'theme-dark-blue'    
     };
     }

在app.module中,我已经注册了该组件,并且在我定义了架构的组件中,

    {
    key: 'date1',
    type: 'bsdatepicker',
    templateOptions: {
      label :'From Date',
      required: true
    },
    expressionProperties: {
      //'templateOptions.label': 'From Date'
    }
  },

任何帮助将不胜感激

我正在使用ngx-formly / bootstrap(不使用素材)创建动态UI /表单。我想显示datepicker控件,所以我使用ngx-bootstrap / datepicker显示了custon bsdatepicker控件。但是...

angular ngx-bootstrap ngx-formly
1个回答
0
投票

为现有的UI(例如引导程序)注册自定义字段类型时,您只需要使用定义的form-field包装器来呈现labelvalidation错误:

© www.soinside.com 2019 - 2024. All rights reserved.