我知道大多数人都熟悉dp-date-picker。由于某种原因,我需要将其包装在我自己制作的组件中,其名称为bh-date-picker。问题是我无法清除这个日期选择器和有趣的问题是,第一次清除工作只有!我已经使用NG_VALUE_ACCESSOR来更好地使用这个组件,但出于某种原因我不知道为什么我无法清除它
我为你设计了一个链接,它有一个日期选择器和一个清除按钮,你可以看到它只是第一次工作。
我通过技巧https://stackblitz.com/edit/angular-t9mrgs解决了这个问题
this.ref.dateModel='';
this.ref.dp.inputElement='';
this.ref.dp.inputElementValue='';
this.ref.dp.inputElementContainer.children[0].attributes[2].nodeValue='';
this.ref.dp.inputElementContainer.children[0].attributes[2].textContent='';
this.ref.dp.inputElementContainer.children[0].attributes[2].value='';
this.ref._dateModel='';
this.ref.dp.api.open();
this.ref.dp.api.close();
在这里你可以看到打开和关闭datepicker可以解决问题我不知道它的最佳解决方案,但它解决了我的问题