我寫我自己的自定義表單元素DateInputComponent
通過實施ControlValueAccessor
和使用它像這樣:如何訪問NgFormControl定製NG2表單元素
<my-date-input ngControl="date"></my-date-input>
從我個人理解,ngControl
是[ngFormControl]="myControlGroup.controls['date']"
語法糖。
現在,在我的DateInputComponent
裏我想訪問NgFormControl
。
我試圖將它與@Input NgFormControl ngFormControl;
綁定,但它永遠不會被設置,我試圖用DateInputComponent(NgFormControl ngFormControl)
注入它,但由於沒有提供程序而失敗。
什麼是正確的方法來得到它?
(也許我也快到了錯誤的方式...我想這DateInputComponent
能夠通過自身來顯示所有驗證錯誤可能發生。)
'ngFormControl'從哪裏來? – yurzui
正如我所說,根據我的理解,'ngControl =「date」'是用於分配此屬性的語法糖。 – enyo