Add pipe to formControl angular2 Reagent Forms

1

My question is that, how can I add a pipe like that to a reactive form, for non-reactive cases, I have seen that it can be done in the following way.

<input [ngModel]="item.value | useMyPipeToFormatThatValue" 
      (ngModelChange)="item.value=$event" name="inputField" type="text" />

Now I am using the angular form reagents2, and that doubt arose, this is my html code.

<form [formGroup]='fb'>
    <input type="text" [formControl]='searchTerm'>
    <button (click)="formClick()">FormClick</button>
    <input type="text" [formControl]="masterValue">
</form>

<ul>
    <li *ngFor="let user of users">
        {{user.name}}
    </li>
</ul>

<p>{{master | masterPipe}}</p>

my MasterPipe.ts

    export class MasterPipe implements PipeTransform{
    transform(master:string){
        const market=4;
        let oculto=master.slice(0,-market);
        let visible=master.slice(-market);
        let a:string=oculto.replace(/./g,'*')+visible;
        return a;
    }
}

I want to add that pipe to the input with the formControl = masterValue, something like this in the line below but in the same input.

<p>{{master | masterPipe}}</p>
    
asked by Kevin AB 27.03.2017 в 19:40
source

1 answer

0

You could subscribe to the changes in the value of the input and each time the event is launched, pass the same filtering logic that you would have in the input, but having it in a method within that component.

    
answered by 05.04.2017 в 15:14