1

我将模式日期用于 bsDatepicker 并且工作正常。

<input type="text" class="form-control" formControlName="birthday" bsDatepicker [bsConfig]="bsConfig" [(bsValue)]="birthday" value="{{dataNascimento | date:'dd/MM/yyyy - dd/MM/yyyy' }}" />

但是在 bsDaterangepicker 中不起作用

<input class="form-control" #drp="bsDaterangepicker" bsDaterangepicker [bsConfig]="bsConfig" [maxDate]="bsConfig.maxDate" value="{{periodo | date:'dd/MM/yyyy - dd/MM/yyyy' }}" />

错误信息

ERROR Error: InvalidPipeArgument: 'Wed Nov 22 2017 12:50:19 GMT-0200 (Horário brasileiro de verão),Wed Nov 22 2017 12:50:19 GMT-0200 (Horário brasileiro de verão)' for pipe 'DatePipe'

ngx-bootstrap、Angular 和 Bootstrap 的版本:

ngx-bootstrap:2.0.0-beta.8

角度:5.0.0

引导程序:3.3.7

构建系统:Angular CLI 1.5.2

问题

谁来为 Daterangepicker 定义日期模式?

4

2 回答 2

1

可能这也将是工作。您可以在 HTML 中使用:

<input class="form-control" bsDaterangepicker id="rangedagte" type="text" [bsConfig]="bsConfig" [(ngModel)]="bsRangeValue" (bsValueChange)="selectRange($event)" />

在组件范围内,它们具有rangeInputFormat您的格式的属性,bsConfig我们可以配置。

export class DateComponent implements OnInit {

initialDate = new Date();
  bsRangeValue: Date[];
  maxDate = new Date();
  bsConfig: Partial<BsDatepickerConfig> = new BsDatepickerConfig();

constructor() {
    this.maxDate.setDate(this.maxDate.getDate() + 7);
    this.bsRangeValue = [this.initialDate, this.maxDate];
  }

  ngOnInit() {
    this.bsConfig = Object.assign({}, { showWeekNumbers: false, containerClass: 'theme-blue', rangeInputFormat: 'DD/MMM/YYYY' });

   }
}
于 2018-12-19T11:30:09.687 回答
0

是的,因为对于他们具有rangeInputFormat您的格式的属性的范围,即rangeInputFormat: 'DD-MM-YYY'

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

于 2018-04-19T13:59:13.017 回答