gpt4 book ai didi

angular - 名称为 : 'dateTime' 的表单控件没有值访问器

转载 作者:太空狗 更新时间:2023-10-29 18:06:44 28 4
gpt4 key购买 nike

我正在尝试为日期时间选择器应用外部库。我收到如下错误:

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'

我的代码如下:

模板:

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

组件:

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)
};

最佳答案

外部库需要一个 ControlValueAccessor 来处理 Angular 形式。

尝试像这样添加 ngDefaultControl:

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

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

看这里:

What is ngDefaultControl in Angular?

关于angular - 名称为 : 'dateTime' 的表单控件没有值访问器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47981627/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com