我使用ngx-formly/bootstrap创建动态UI/表单(不使用material)。我想要显示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="" 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'
}
},任何帮助我们都将不胜感激。
发布于 2020-03-12 21:12:02
在为已经存在的UI注册自定义字段类型时,例如bootstrap,您只需要使用定义的form-field包装器来呈现label和validation错误:
@NgModule({
imports: [
FormlyModule.forRoot({
types: [
{
name: 'bsdatepicker',
...
wrappers: ['form-field']
},
],
}),
],
})
export class AppModule { }https://stackoverflow.com/questions/60651794
复制相似问题