AngularMaterialDatepicker选择策略-如何获取所选日期范围的值
创始人
2024-10-28 08:33:06
0

在使用Angular Material Datepicker时,您可以使用mat-date-range-input指令将开始和结束日期选择器组合起来,以便选择日期范围。但是,如果您想获取这个选择器所选日期范围的值,您需要使用Angular Material Datepicker的选择策略API。

以下示例显示如何使用选择策略来获取所选日期范围的值。 要获取所选日期范围,请使用selectionChanged事件,并将当前日期范围作为参数传递。 请注意,这将返回一个MatDateSelectionModel对象,该对象包含开始和结束日期。


  
    
    
  
  
  

import { Component } from '@angular/core';
import { FormControl } from '@angular/forms';
import { MatDateSelectionModel, MatDateRangeSelectionStrategy } from '@angular/material/datepicker';

@Component({
  selector: 'app-datepicker-range-example',
  templateUrl: 'datepicker-range-example.html',
  styleUrls: ['datepicker-range-example.css'],
})
export class DatepickerRangeExample {
  startDate = new FormControl();
  endDate = new FormControl();

  constructor(private selectionStrategy: MatDateRangeSelectionStrategy) {}

  onSelect(selection: MatDateSelectionModel): void {
    const range = this.selectionStrategy.selectionFinished(
      selection.selection, selection.source === 'start' ? 'end' : 'start'
    );
    if (range.start && range.end) {
      console.log('Range:', range);
    }
  }
}

相关内容

热门资讯

必备辅助推荐!德普之星私人局辅... 必备辅助推荐!德普之星私人局辅助免费(辅助挂)一直是真的有挂(有挂方针)一、德普之星私人局辅助免费可...
分享实测!约局吧是否有挂(辅助... 分享实测!约局吧是否有挂(辅助挂)一直真的有挂(的确有挂)约局吧是否有挂辅助器是一种具有地方特色的麻...
揭秘攻略!wepoker怎么挂... 您好,wepoker怎么挂底牌这款游戏可以开挂的,确实是有挂的,需要了解加去威信【136704302...
记者爆料!aapoker透视脚... 记者爆料!aapoker透视脚本下载(辅助挂)原来存在有挂(发现有挂)1、该软件可以轻松地帮助玩家将...
重磅来袭!hhpoker脚本下... 重磅来袭!hhpoker脚本下载(辅助挂)一贯真的有挂(有挂方略)1、每一步都需要思考,不同水平的挑...
玩家必备教程!wpk模拟器是什... 玩家必备教程!wpk模拟器是什么(辅助挂)真是有挂(有挂功能)1、该软件可以轻松地帮助玩家将wpk模...
科普常识!pokerworld... 科普常识!pokerworld修改器(辅助挂)竟然有挂(新版有挂)pokerworld修改器脚本下载...
一分钟了解!epoker有透视... 一分钟了解!epoker有透视吗(辅助挂)原来存在有挂(有人有挂)1、epoker有透视吗脚本辅助下...
热点讨论!wepoker辅助器... 热点讨论!wepoker辅助器有哪些功能(辅助挂)果然存在有挂(有挂方法)该软件可以轻松地帮助玩家将...
揭秘关于!wejoker透视方... 揭秘关于!wejoker透视方法(辅助挂)原来是真的有挂(有挂透明挂)1、在wejoker透视方法插...