Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/reporting-services/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angular 如何提供另一个控件值访问器?_Angular_Typescript_Angular Directive_Angular Di - Fatal编程技术网

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

Angular 如何提供另一个控件值访问器?,angular,typescript,angular-directive,angular-di,Angular,Typescript,Angular Directive,Angular Di,我已经有一个指令正在实现ControlValueAccessor接口(指令的选择器是input[type=date]),我需要另一个指令来实现ControlValueAccessor和选择器input[type=datepicker][datepicker]——我们称之为datepicker指令 如您所见,这些指令的选择器相互覆盖,当我使用datepicker指令时,出现以下错误: ERROR Error: Uncaught (in promise): Error: More than one

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

如您所见,这些指令的选择器相互覆盖,当我使用datepicker指令时,出现以下错误:

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


所以我有一个想法,也许我可以告诉angular在可能的情况下提供datepicker指令,但是如何做到呢?

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

首先是

input[type=date]:not([datepicker])
第二个呢

input[type=date][datepicker]

哇,好主意,我现在就用它,但我还是很好奇是否有提供控件值访问器的方法-至少内置指令没有这样的问题,但是它们选择器像我的例子中那样相互覆盖。DefaultValueAccessor()-只有
[type=checkbox]
使用了相同的技巧,但也有其他的访问器,例如number(),这些技巧似乎不是必需的。我不知道您的情况,但我在这两个选项中看到了我刚才提供给您的相同选择器逻辑!一点也不,对于使用
:not([type=checkbox])
DefaultValueAccessor
,这是正确的,但同时它没有使用
:not([type=number])
,但是
NumberValueAccessor
存在,或者我遗漏了什么?糟糕,我明白你的意思了。对不起,我帮不了你,我通常依靠选择器来避免冲突。。。