Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
971 views
in Technique[技术] by (71.8m points)

datepicker - How to bind the date (from & to) to an angular 9 date picker field after backend api responsed?

I'm using below lines to show the from and to date fields:

<mat-form-field>
  <mat-label> Valid From </mat-label>
  <input matInput #resultFromPickerModel="ngModel" [(ngModel)]="fromDate" [matDatepicker]="fromDatePicker"
  (dateChange)="addEvent($event.target.value, $event, 'from')">
  <mat-datepicker-toggle [for]= "fromDatePicker" matSuffix></mat-datepicker-toggle>
  <mat-datepicker #fromDatePicker></mat-datepicker>
  <mat-error *ngIf="resultFromPickerModel.hasError('matDatepickerParse')">
    Valid From - Invalid Date
   </mat-error>
</mat-form-field>
<mat-form-field>
  <mat-label> Valid To </mat-label>
  <input matInput #resultToPickerModel="ngModel" [(ngModel)]="toDate" [matDatepicker]="toDatePicker"
  (dateChange)="addEvent($event.target.value, $event, 'to')">
  <mat-datepicker-toggle [for]= "toDatePicker" matSuffix></mat-datepicker-toggle>
  <mat-datepicker #toDatePicker></mat-datepicker>
  <mat-error *ngIf="resultToPickerModel.hasError('matDatepickerParse')">
    Valid To - Invalid Date
  </mat-error>
</mat-form-field>

Once the backend response with data, we are showing an table as in below image (Document tab

I want to pre fill the from and to date fields in Document tab, whenever we have the date value in history tab as in below image History tab

I'm storing the date value which I have received in History tab under an shared service, so that I can get the same value in Documents tab.

But the problem I'm facing is "unable to fill the date value into from and to date fields. Even thought I'm able to get the data from shared service".

Below is the method which does the table creation and filling of from & to date fields in Documents tab.

prepareData(): void {
    .................
    this.dataSource = ....... : new MatTableDataSource([]);
    this.utils.currentMessage.subscribe(message => (this.selectedMessage = message));
    //logic to fill from and to dates      
  }

Could you please anyone tell me, how can I prefill the from & to date filed (with invalid date validation - already there in the code) and preform the filter on table based on the from & to dates. (note: already I have the table filtering logic)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...