Site icon 峰哥分享

Angular 2+ Use pipe for reactive form controls

With Angular Reactive Form, your input value is automatically read from formControlName binding, which is defined in the type script file.
There is no way you can use angular pipe in typescript. How would you pipe the formControl value?
In the following example, I would like to pipe the string ISO date to local date.

 <mat-form-field> <input matInput name="createdDate" readonly placeholder="Created Date:" formControlName="createdDate"> </mat-form-field> 

Here is how I did it.

 <mat-form-field> <input matInput name="createdDate" readonly placeholder="Created Date:" formControlName="createdDate" &#91;value&#93;="organizationForm.value.createdDate | date"> </mat-form-field> 
Exit mobile version