angulartypescriptangular-directiveangular-di

how to provide another control value accessor?


I've already got a directive what is implementing the ControlValueAccessor interface (directive's selector is input[type=date]) and I need to have another directive implementing ControlValueAccessor with selector input[type=date][datepicker] - let's call it the datepicker directive.

As you can see the selectors of those directives are covering each other and I'm getting following error when I'm using the datepicker directive:

ERROR Error: Uncaught (in promise): Error: More than one custom value accessor matches form control with unspecified name attribute

the error is thrown there: https://github.com/angular/angular/blob/5.2.x/packages/forms/src/directives/shared.ts#L206

so I've got an idea that maybe I could somehow tell angular to provide the datepicker directive when it is possible, but how to do that?


Solution

  • Why not simply play with the selectors ?

    The first would be

    input[type=date]:not([datepicker])
    

    And second one

    input[type=date][datepicker]