Angular 个日期选择器,共 bootstrap 个

Angular ng-bootstrap Datepicker

在 Angular ng-bootstrap datepicker Site link here 中,在 Range Selection 部分,同时从 Typecript 获取代码section 有一个 import "import {after, before, equals} from './tools';".

在类?

之前我们可以从哪里得到这个

我们从哪里获得提到的 tools 文件或者我们可以从哪里获得该文件?

https://github.com/ng-bootstrap/ng-bootstrap/blob/master/demo/src/app/components/datepicker/demos/range/datepicker-range.ts

它似乎是在数据选择器范围内定义的。 但是它不是从这里导出的。

它似乎也在这里: https://github.com/ng-bootstrap/ng-bootstrap/blob/master/src/datepicker/ngb-date.ts

这个导出为 NgbDate,所以你应该能够做到:

import { NgbDate  } from '@ng-bootstrap/datepicker/ngb-date';
...
NgbDate.after

您可能需要稍微弄乱路径(但我没有看到将它拉到一起的索引文件。

提到的 tools.ts 文件的目的是位于该文件中的实用程序将由应用程序开发人员提供。目前这些还不是 ng-bootstrap 库的一部分,但我们计划在该功能中发布类似的实用程序。

更糟糕的是,我们在演示页面中有一个错误,并且无法从 tools.ts 文件的来源及其内容中明显看出。该错误现已修复,您可以在 https://ng-bootstrap.github.io/#/components/datepicker/examples

看到一个工作示例

作为参考,tools.ts 文件包含以下实用程序(我们已将此文件删除到最新的演示版本中,并将内联实用程序作为演示的一部分):

const equals = (one: NgbDateStruct, two: NgbDateStruct) =>
  one && two && two.year === one.year && two.month === one.month && two.day === one.day;

const before = (one: NgbDateStruct, two: NgbDateStruct) =>
  !one || !two ? false : one.year === two.year ? one.month === two.month ? one.day === two.day
    ? false : one.day < two.day : one.month < two.month : one.year < two.year;

const after = (one: NgbDateStruct, two: NgbDateStruct) =>
  !one || !two ? false : one.year === two.year ? one.month === two.month ? one.day === two.day
    ? false : one.day > two.day : one.month > two.month : one.year > two.year;

您可以在从演示页面分叉出来的插件中看到这一切:http://plnkr.co/edit/2I13mvvJBSpX9jyG4p5V?p=preview

import { NgbDate } from '@ng-bootstrap/ng-bootstrap/datepicker/ngb-date'

这有效!!