No value accessor for form control with name: 'dateTime'
Asked Answered
D

1

5

I am trying to apply external library for datetime picker. I am getting an error like below:

ERROR Error: Uncaught (in promise): Error: No value accessor for form control with name: 'dateTimeDeparture'
Error: No value accessor for form control with name: 'dateTimeDeparture'

My code is below:

Template:

<owl-dateTime-input [(ngModel)]="flightDetails.dateTimeDeparture" name="dateTimeDeparture" [locale]="en" required></owl-dateTime-input>  

Component:

this.en = {
    firstDayOfWeek: 0,
    dayNames: ["Sunday", "Monday", "Tuesday","Wednesday", "Thursday", "Friday", "Saturday"],
    dayNamesShort: ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"],
    monthNames: [ "January","February","March","April","May","June","July","August","September","October","November","December" ],
    monthNamesShort: [ "Jan", "Feb", "Mar", "Apr", "May", "Jun","Jul", "Aug", "Sep", "Oct", "Nov", "Dec" ]
};

this.flightDetails = {
    dateTimeDeparture: new Date(2017, 8, 10, 13, 30, 30),
    dateTimeArrival: new Date(2017, 8, 10, 13, 30, 30)
};
Damondamour answered 26/12, 2017 at 17:13 Comment(0)
B
14

External library require a ControlValueAccessor to work with angular forms.

Try to add ngDefaultControl like this:

<owl-dateTime-input [(ngModel)]="flightDetails.dateTimeDeparture" name="dateTimeDeparture" [locale]="en" required formControlName="dateTimeDeparture" ngDefaultControl></owl-dateTime-input>

or

<owl-dateTime-input [(ngModel)]="flightDetails.dateTimeDeparture" name="dateTimeDeparture" [locale]="en" required ngDefaultControl></owl-dateTime-input>

Look here:

What is ngDefaultControl in Angular?

Boche answered 26/12, 2017 at 17:32 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.