ngOnInit method

  1. @override
void ngOnInit()

Executed after the first change detection run for a directive.

See OnInit for a full description.

Implementation

@override
void ngOnInit() {
  model
    ..minDate = minDate
    ..maxDate = maxDate
    ..requireFullPeriods = requireFullPeriods
    ..basic = isBasic;
  if (selection.value != null) {
    model.value = _maybeStripComparison(selection.value);
  }
  _disposer.addFunction(model.dispose);

  bool _needsApply(DatepickerComparison modelValue) =>
      modelValue != selection.value || !_isPreset(modelValue);

  // Wire the internal model and the external value up to each other.
  _updateFormattedRanges(selection.value);
  _disposer
    ..addDisposable(selection.stream.listen((v) {
      model.value = _maybeStripComparison(v);
      _updateFormattedRanges(v);
    }))
    ..addDisposable(model.changes
        .map((v) => v.date)
        .map(_needsApply)
        .listen(_showApplyBar))
    ..addDisposable(model.changes
        .where((_) => !_popupVisible) // handle next/prev buttons while closed
        .listen((v) => selection.value = v.date));
}