Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

No value accessor for form control with name: 'dateTime'

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)
};
like image 218
raj m Avatar asked Dec 14 '22 19:12

raj m


1 Answers

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?

like image 88
HDJEMAI Avatar answered Dec 29 '22 09:12

HDJEMAI