ng2-ui / datetime-picker

Angular2 DateTime Picker
https://ng2-ui.github.io/#/datetime-picker
MIT License
121 stars 62 forks source link

Form.controls value null if not using ngModel #109

Closed youngzkyz closed 7 years ago

youngzkyz commented 7 years ago

Thanks before,

I have been test for my component if i dont using ([ngModel]). the form dont detect changes so the value still null or not changed.

here check my plunker

How to solve this?

Thanks,

allenhwkim commented 7 years ago

Thanks for feedback

Please take a look at this example, https://rawgit.com/ng2-ui/ng2-datetime-picker/master/app/index.html

I am not sure this is the right approach, but to make it work, you need to have formControlName="xxx" for the input field.

    <input formControlName="birthDate" ng2-datetime-picker>

https://plnkr.co/edit/W5YtoN?p=preview

This is currently how we get a AbstractControl for the input field, but I am not sure this is the right approach.

https://github.com/ng2-ui/ng2-datetime-picker/blob/master/src/ng2-datetime-picker.directive.ts#L111

I would appreciate if you suggest anything we can make use of [formControl], in addition to the usage of formControlName

[formControl] and formControlName are both correct AFAIK.

Reference: