简体   繁体   English

PrimeNG日历未在模态中反映日期

[英]PrimeNG Calendar not reflecting date in modal

I am using PrimeNG Calendar control I am able to select and store date but when I fetch dates from say database and trying to set it by updating Modal. 我正在使用PrimeNG Calendar控件,我可以选择和存储日期,但是当我从数据库中获取日期并尝试通过更新Modal进行设置时。 I am getting the following error : 我收到以下错误:

在此处输入图片说明

<p-calendar  [(ngModel)]="bin.bidinstalledfrom" dateFormat="dd/mm/yy" 
[showTime]="true"  autocomplete="off" required name="BIDInstalledFrom" 
id="installedfrom" class="col-md-12"  ></p-calendar>

Component: 零件:

 this.bin.BIDInstalledFrom='17/05/2018'
;// I have hardcoded the date in component for the ease of development

I have tried dates in various formats. 我尝试过各种格式的日期。 '17/05/2018 16:00', '17/05/2018','1526572848' etc '17 / 05/2018 16:00','17/05/2018','1526572848'等

I have also tried changing the datatype of modal property bidinstalledfrom to string,date,number. 我还尝试将模式属性bidinstalledfrom从的数据类型更改为string,date,number。 Same issue. 同样的问题。 And since I am getting error, not only am I not able to set the date but also calendar doesn't work. 而且由于出现错误,我不仅无法设置日期,而且日历也无法使用。

What am I missing here? 我在这里想念什么?

Primeng Calendar accepts Date object. Primeng日历接受Date对象。 So you have to convert your date string to JS date object. 因此,您必须将日期字符串转换为JS日期对象。 Eg: 例如:

new Date('17/05/2018');

And then assign it to your model. 然后将其分配给您的模型。

For PrimeNG Calendar you need to use the JavaScript Date object and do the instantiation correctly. 对于PrimeNG日历,您需要使用JavaScript Date对象并正确进行实例化。 For instance with new Date('mm/dd/yyyy') (see https://www.w3schools.com/js/js_dates.asp and https://www.w3schools.com/js/js_date_formats.asp ). 例如,使用new Date('mm/dd/yyyy') (请参阅https://www.w3schools.com/js/js_dates.asphttps://www.w3schools.com/js/js_date_formats.asp )。

Template: 模板:

<p-calendar [(ngModel)]="bin.bidinstalledfrom" 
            [showTime]="true"
            dateFormat="dd/mm/yy">
</p-calendar>

Component: 零件:

this.bin.bidinstalledfrom = new Date('05/17/2018');

You can find a working demo here: https://stackblitz.com/edit/prime-ng-calendar-38du98 您可以在这里找到有效的演示: https : //stackblitz.com/edit/prime-ng-calendar-38du98

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM