【问题标题】:Calendar PrimeNG does not work日历 PrimeNG 不起作用
【发布时间】:2018-07-19 11:02:05
【问题描述】:

我已经安装了 PrimeNG 并想使用它的日历组件。因此,我制作了一个 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 ERROR 错误:没有未指定名称属性的表单控件的值访问器

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

【问题讨论】:

    标签: angular primeng


    【解决方案1】:

    你的日历应该有 name 属性,

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

    【讨论】:

      【解决方案2】:

      问题在于 App Module 中缺少 CalendarModule。 (我已经将它导入到 MyCalendar 模块中)。

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

      【讨论】:

        猜你喜欢
        • 2022-12-31
        • 2020-12-28
        • 1970-01-01
        • 1970-01-01
        • 2022-12-11
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多