如何在 angular dart 中从 Material 日期范围选择器输出值

How to output values from Material date range picker in angular dart

如何从 angular dart 中的 material-date-range-picker 列表中获取值?

https://dart-lang.github.io/angular_components/#/material_datepicker

<ul>
    <li *ngFor="let rangeSimplified of datepickerComparisonList">
        <material-date-range-picker
            compact
            [range]="rangeSimplified"=
            [(minDate)]="minDate"
            [(maxDate)]="maxDate"
            [(outputDateFormat)]="outputDateFormat"
            [required]="true">
        </material-date-range-picker>
    </li>
</ul>

我想获取用户选择的所有时间段的值数组。

我能够解决我的问题

这是一个示例项目:

飞镖:

import 'package:angular/angular.dart';
import 'package:angular_components/angular_components.dart';

// AngularDart info: https://webdev.dartlang.org/angular
// Components info: https://webdev.dartlang.org/components

@Component(
  selector: 'my-app',
  styleUrls: ['app_component.css'],
  templateUrl: 'app_component.html',
  directives: [
    NgIf,
    NgFor,
    MaterialDateRangePickerComponent,
    MaterialButtonComponent,
  ],
  providers: [
    datepickerBindings,
  ]
)
class AppComponent {
  AppComponent();

  String _log = '';
  String get log => this._log;
  set log(String value) {
    print(value);
    this._log += '\n$value';
  }

  List<DateRangeTile> rangeTileList = <DateRangeTile>[];

  void rmRange() {
    rangeTileList.removeLast();
  }

  void addRange() {
    this.rangeTileList.add(DateRangeTile());
  }

  void checkDateRange() {
    log = '';
    log = '### Ranges:';
    for (DateRangeTile rangeTile in this.rangeTileList) {
      log = '${rangeTile.range.toString()}';
    }
    log = '### ### ###';
    log = '';
  }
}

class DateRangeTile {
  DatepickerComparison _range;
  DatepickerComparison get range => this._range;
  set range(DatepickerComparison value) {
    this._range = value;
  }

  DateRangeTile();

  /*
  // DatepickerComparison sample
  DatepickerComparison.previousPeriod(
    DatepickerDateRange.custom(
      Date.today().add(days: 3),
      Date.today().add(days: 4),
    ),
  ),
  */
}

HTML

<h3>DateRangePicker list</h3>
<div *ngFor="let rangeTile of rangeTileList">
    <material-date-range-picker [(range)]="rangeTile.range"></material-date-range-picker>
    <br>
</div>

<material-button *ngIf="rangeTileList.length == 0" disabled class="float-left">REMOVE</material-button>
<material-button *ngIf="rangeTileList.length > 0" raised (click)="rmRange()" class="float-left">REMOVE</material-button>
<material-button raised (click)="addRange()" class="float-left">ADD</material-button>
<material-button raised (click)="checkDateRange()" class="float-left">CHECK</material-button>

<pre>{{log}}</pre>

CSS

:host {
    /* This is equivalent of the 'body' selector of a page. */
}

.float-left {
    float: left;
}