0

我正在创建一个类似于http://api.example.com?startdate_30.12.2018&enddate_30.12.2018的 API 路径,其中我使用 2 个输入日期字段来生成日期值。

这是我的代码:

    import { Component, OnInit } from '@angular/core';
    import { FormControl } from '@angular/forms';
    import { DefaultFilter } from './default-filter';
    import { merge, combineLatest } from 'rxjs';

    @Component({
      selector: 'date-filter',
      template: `
        <input type="date" [(ngModel)]="query" [formControl]="startDate" [ngClass]="inputClass" class="form-control">
        <input type="date" [formControl]="endDate" [ngClass]="inputClass" class="form-control">
     `,
    })
    export class DateFilterComponent extends DefaultFilter implements OnInit {
      startDate = new FormControl();
      endDate = new FormControl();
      constructor() {
        super();
      }
    ngOnInit() {
      this.changesSubscription = combineLatest(this.startDate.valueChanges, this.endDate.valueChanges).subscribe(([value1, value2]) => this.setFilter());
    }

我使用 combineLatest 合并 2 个 Observables,它产生一个数组作为值,this.setFilter() 使用字符串作为值,如何将其更改为字符串。

我也使用过mergeMap,但它没有用。

4

1 回答 1

1
 this.changesSubscription = combineLatest(this.startDate.valueChanges, this.endDate.valueChanges)
.pipe(
  map(([value1, value2]) => value1 + value2)
)
.subscribe(value) => this.setFilter(value));
于 2018-08-03T11:40:24.860 回答