1

I'm wondering if it is possible to create custom input types other than the native ones that are listed here

If it's possible, how? I'm thinking of a directive which preserves the native input types but extends it with new, custom ones with custom functionality.

e.g. I want to have a IBAN input type, that has a input mask & validation given because of the directive:

<input type="iban" [(ngModel)]="iban" />

Hope someone can help me out with that!

Yassine Zeriouh
  • 480
  • 3
  • 10
  • 23
  • Possible duplicate of [How to create a custom input type?](https://stackoverflow.com/questions/14736469/how-to-create-a-custom-input-type) – Ephi Mar 22 '19 at 14:26
  • 2
    not a duplicate of above - different frameworks – Joey Gough Mar 22 '19 at 14:29
  • 1
    That duplicate question is for AngularJS (1.x). You wouldn't actually make a new type for input, those are effectively controlled by the browser(s). Instead you would use an existing type, such as `text` and wrap a component around it. You would connect this component as a "custom control" that then can be used with reactive and/or template driven forms. This is effectively how frameworks such as material make custom inputs. There are **many** examples of creating custom input control components, such as https://blog.thoughtram.io/angular/2016/07/27/custom-form-controls-in-angular-2.html – Alexander Staroselsky Mar 22 '19 at 14:30
  • I think what you are actually needing is a new component. You would not use `input` element directly, that is something the new component would then do within it's template. The caller would then pass an instance of the `IBAN` type (class or interface) to the component. – Igor Mar 22 '19 at 14:32
  • you can use a directive ``. I don't know if work using as selector of the directive some like `selector:"input[type='iban']"` – Eliseo Mar 22 '19 at 15:16

0 Answers0