昨天,今天,明天,每天的每天,你是否都多懂得一点点...

星期五, 九月 28, 2018

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.

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

Here is how I did it.

[html]
    <mat-form-field>
      <input matInput name="createdDate" readonly placeholder="Created Date:" formControlName="createdDate" [value]="organizationForm.value.createdDate | date">
    </mat-form-field>
[/html]

--
Feng

没有评论:

其它博客地址

此博客的同步博客地址: http://fengnz.wordpress.com
这里进入我的MSN SPACE.