我正在尝试在旧的日期选择器上应用区域设置
https://valor-software.com/ngx-bootstrap/#/datepicker
我已经尝试过一切,但我不知道在哪里进一步寻找,我可以使用新的,但我有一个很大的解决方案,我必须留在旧的日期选择器上
这就是我所拥有的
my.module.ts
import { CommonModule } from '@angular/common';
import { DatepickerModule } from 'ngx-bootstrap/datepicker';
@NgModule({
imports: [
DatepickerModule.forRoot()
],
declarations: [
],
providers: [
],
schemas: [
CUSTOM_ELEMENTS_SCHEMA
]
})
export class MyModule {
}
my.component.ts
import { defineLocale } from 'ngx-bootstrap/bs-moment';
import { de } from 'ngx-bootstrap/locale';
defineLocale('de', de);
@Component({
templateUrl: './my.component.html',
styleUrls: ['./my.component.scss']
})
export class MyComponent implements OnInit {}
my.component.html
<datepicker formControlName="effectiveDate" [showWeeks]="false" [locale]="de">
无法绑定到“区域设置”,因为它不是“日期选择器”的已知属性。 :(
此日期选择器的旧版本不包含
locale
输入。文档指出 This is a legacy version of datepicker without support of daterangepicker, locales, themes, etc.
新版本确实有区域设置,但不能将其作为输入属性进行修改。相反,您可以使用 BsLocaleService
来更改区域设置。它应该看起来像这样:
my.module.ts
import { CommonModule } from '@angular/common';
import { BsDatepickerModule, BsLocaleService } from 'ngx-bootstrap/datepicker';
import { de } from 'ngx-bootstrap/locale';
defineLocale('de', de);
@NgModule({
imports: [
BsDatepickerModule.forRoot()
],
declarations: [
],
providers: [
BsLocaleService
],
schemas: [
CUSTOM_ELEMENTS_SCHEMA
]
})
export class MyModule {
}
my.component.ts
import { BsDatepickerConfig, BsLocaleService } from 'ngx-bootstrap/datepicker';
import { listLocales } from 'ngx-bootstrap/bs-moment';
@Component({
templateUrl: './my.component.html',
styleUrls: ['./my.component.scss']
})
export class MyComponent implements OnInit {
locale = 'de';
constructor(private _localeService: BsLocaleService) {}
ngOnInit(){
this._localeService.use(this.locale);
}
}
my.component.html
<input placeholder="Datepicker" type="text" formControlName="effectiveDate" class="form-control" bsDatepicker #dp="bsDatepicker">