Pk.
Pk.

Reputation: 7

How to bind custome pipe with reactive form input box Angular 4

How to bind custom pipe with reactive form input box Angular 4.

Please check the working code.

<input [ngModel]="datevalue | datePipe"
       (ngModelChange)="datevalue=$event"
       name="dateField"
       type="text" />

But I want to bind With

<input type="text" name="dt" formControlName="dt">

Upvotes: 1

Views: 144

Answers (1)

Suren Srapyan
Suren Srapyan

Reputation: 68665

If you need to use this kind of input in many places, you can create a control which implements ControlValueAccessor and encapsulates this kind of work under the hood. And in other places you can just use

<my-control type="text" name = "dt" formControlName="dt"></my-control>

which under it will contain something like

<input [ngModel]="datevalue | datePipe"
       (ngModelChange)="datevalue=$event"
       name="dateField"
       type="text" />

Upvotes: 1

Related Questions