kevinoleary19 / Angular-2-Datepicker

A minimalist datepicker inspired by Google's material design
70 stars 71 forks source link

Using formControlName with material-datepicker gives No value accessor for form control #80

Open Jagpreet16 opened 7 years ago

Jagpreet16 commented 7 years ago

Please help me on below. I am using material-datepicker with reactive forms.

I am getting the following error when the form loads. Error: No value accessor for form control with name: 'birthday' at _throwError (shared.js:122) [angular] at setUpControl (shared.js:35) [angular] at FormGroupDirective.addControl (form_group_directive.js:124) [angular] at FormControlName._setUpControl (form_control_name.js:193) [angular] at FormControlName.ngOnChanges (form_control_name.js:111) [angular]
ChristopherLaytonWasTakenSoIWentWithT commented 7 years ago

This is due to the fact the library doesn't use the ControlValueAccessor. I plan on forking and updating this as it seems development for this repo may be dead.

What you can do is wrap it with a component that implments ControlValueAccessor to have it work properly with NgModel and all the Angular/Form stuff.

https://blog.thoughtram.io/angular/2016/07/27/custom-form-controls-in-angular-2.html

This post has a really detailed example of what needs to be done.

Hope all is well, C Layton

ChristopherLaytonWasTakenSoIWentWithT commented 6 years ago

105 is a PR made to solve this... Though maybe we all should just fork and solve this ourselves

alanent commented 6 years ago

Someone can watch this please ? https://stackoverflow.com/questions/50947642/angular-material-6-datepicker-reactive-form