0

I am new to Angular, and I want to format my input value for my date picker, but I cannot figure out how. I want to do something like this:

    <mat-date-range-input [rangePicker]="picker">
    <input
      class="hide"
      matStartDate
      [value]="startDate | date: 'shortDate': '' "
      #dateRangeStart
      placeholder="Start date"
    />
    <input
      class="hide"
      matEndDate
      [value]="endDate | date: 'shortDate': '' "
      placeholder="End date"
      [max]="today"
      #dateRangeEnd
      (dateChange)="dateRangeChange(dateRangeStart, dateRangeEnd)"
    />
    />
1

1 Answer 1

1

Import DatePipe in .ts:

import {DatePipe} from '@angular/common';

constructor(private datePipe: DatePipe) {}

In app.module.ts, import DatePipe and add it in providers:

providers: [DatePipe]

Add the following in your dateChange function:

dateRangeChange (dateRangeStart, dateRangeEnd) {
    startDate = this.datePipe.transform(dateRangeStart, 'yyyy-MM-dd');
    endDate = this.datePipe.transform(dateRangeEnd, 'yyyy-MM-dd');
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.