How can I create my own component for FormControls?

后端 未结 2 1904
后悔当初
后悔当初 2021-01-03 15:25

I would like to create a form and use a new, custom component for its controls. So I created a new component and included it into the parent form. But although the parent fo

2条回答
  •  刺人心
    刺人心 (楼主)
    2021-01-03 16:00

    I played around with the accepted answer for a long time, and never had any luck.

    I had much better results implementing the ControlValueAccessor interface as shown here: https://alligator.io/angular/custom-form-control/

    It's actually pretty simple, I also rigged up an Example StackBlitz

提交回复
热议问题