繁体   English   中英

日期选择器 ngx-bootstrap

[英]Datepicker ngx-bootstrap

我正在尝试在旧日期选择器上应用语言环境

https://valor-software.com/ngx-bootstrap/#/datepicker

我已经尝试了 evrything,但我不知道该往哪里看,我可以使用新的,但我有一个很大的解决方案,我必须留在旧的 datepicker

这是我所拥有的

我的.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 {
}

我的.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 {}

我的.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来更改语言环境。 它应该看起来像这样:

我的.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 {
}

我的.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);
   }

}

我的.component.html

<input placeholder="Datepicker" type="text" formControlName="effectiveDate" class="form-control" bsDatepicker #dp="bsDatepicker">

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM