日历PrimeNG不起作用



我已经安装了PrimeNG,并想使用它的Calendar组件。因此,我制作了一个MyCalendar组件:

TS文件:

import { Component } from '@angular/core';
@Component({
selector: 'app-my-calendar',
templateUrl: './my-calendar.component.html',
styleUrls: ['./my-calendar.component.css']
})
export class CalendarDemoComponent  {    
myDate1: Date;       
}

HTML文件:

<div class="ui-g ui-fluid">
<div class="ui-g-12 ui-md-4">
<h3> A simple canedar </h3>
<p-calendar [(ngModel)]="myDate1"></p-calendar> {{myDate1|date}} // line 4
</div>
</div>

通过运行应用程序,我在控制台上得到了这个错误:

CalendarDemoComponent.html:4错误:没有具有未指定名称属性的表单控件的值访问器

你能帮我找出我的代码出了什么问题吗?

问题是应用程序模块中缺少日历模块yCalendar模块中导入了它(。

import {CalendarModule} from 'primeng/calendar';    
imports: [
BrowserModule,
BrowserAnimationsModule,    
CalendarModule
]

您应该拥有日历的名称属性

<p-calendar [(ngModel)]="myDate1" name="date" dateFormat='dd/mm/yy'"></p-calendar>

最新更新