0

I have a pipe I applied to my form input because I want "visually" separate decimals with ",", but internally with "."

Sometimes I need to set values programmatically and in this case the change is not detected even setting my pipe as impure

pipe

@Pipe({
   name: 'decimalSeparator',
   pure: false
})
export class DecimalPipe implements PipeTransform {

  transform(value: string): string {
     return value ? value.replace('.',',') : '';
   }
}

html template

<form [formGroup]="formGroup">
      <input nxInput value="{{ formGroup.get('pipeInput').value | decimalSeparator }}" formControlName="pipeInput"/>
</form>

typescript

setValue() {
   this.formGroup.get('pipeInput').setValue("100.2"); // Pipe not fired here
}
Random
  • 3,158
  • 1
  • 15
  • 25
cucuru
  • 3,456
  • 8
  • 40
  • 74
  • Does this answer your question? [How to use pipes in Angular 5 reactive form input](https://stackoverflow.com/questions/49522542/how-to-use-pipes-in-angular-5-reactive-form-input). You should transform the value with pipe and set to form control as Dallas' answer. – Yong Shun Jun 30 '23 at 05:13

0 Answers0