How can I create custom component which would work just like native <input>
tag? I want to make my custom form control be able to support ngControl, ngForm, [(ngModel)].
As I understand, I need to implement some interfaces to make my own form control work just like native one.
Also, seems like ngForm directive binds only for <input>
tag, is this right? How can i deal with that?
Let me explain why I need this at all. I want to wrap several input elements to make them able to work together as one single input. Is there other way to deal with that? One more time: I want to make this control just like native one. Validation, ngForm, ngModel two way binding and other.
ps: I use Typescript.
I don't understand why every example I find on the internet has to be so complicated. When explaining a new concept, I think it's always best to have the most simple, working example possible. I've distilled it down a little bit:
HTML for external form using component implementing ngModel:
Self-contained component (no separate 'accessor' class - maybe I'm missing the point):
In fact, I've just abstracted all of this stuff to an abstract class which I now extend with every component I need to use ngModel. For me this is a ton of overhead and boilerplate code which I can do without.
Edit: Here it is:
Here's a component that uses it: (TS):
HTML: