How to use pipes in Angular 5 reactive form input

前端 未结 6 912
醉梦人生
醉梦人生 2020-12-13 01:59

I am trying to figure out how to use a pipe within a reactive form so that the input is forced into a currency format. I have already created my own pipe for this which I h

6条回答
  •  星月不相逢
    2020-12-13 03:00

    Without knowing your pipe code, it's likely throwing errors because of where you're constructing that form.

    Try using Angular's change detection hooks to set that value after inputs have been resolved:

    export class MyComponent implements OnInit {
      myForm: FormGroup;
    
      constructor(private builder: FormBuilder) { }    
    
      ngOnInit() {
        this.myForm = builder.group({
          amount: ['', Validators.required]
        });
      }
    
    }
    

提交回复
热议问题