如何提供另一个控制值访问器?

时间:2018-05-15 09:09:11

标签: angular typescript angular-directive angular-di

我已经有一个指令正在实现ControlValueAccessor接口(指令的选择器是input[type=date]),我需要另一个指令实现ControlValueAccessor selector input[type=date][datepicker] - 让它称之为datepicker指令。

正如您所看到的那些指令的选择器相互覆盖,当我使用datepicker指令时,我会收到以下错误:

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

错误发生在那里:https://github.com/angular/angular/blob/5.2.x/packages/forms/src/directives/shared.ts#L206

所以我有一个想法,也许我可以告诉angular在可能的时候提供datepicker指令,但是怎么做?

1 个答案:

答案 0 :(得分:2)

为什么不简单地使用选择器?

第一个是

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

第二个

input[type=date][datepicker]
相关问题