首页 > 解决方案 > 尝试在应用程序中使用 PrimeNG 中的 p-Dropdown 时出错

问题描述

我想在我的应用程序中使用这个 PrimeNG-Dropdown。所以我做了什么:

npm i primeng --save

然后我DropdownModule在我的导入中添加了app.module.ts. 之后,我在我的 html 中包含了以下代码:

<p-dropdown [options]="optionList" [(ngModel)]="selectionString" placeholder="Choose one"></p-dropdown>

在运行ng serve和启动localhost:4200时出现以下错误:

./node_modules/primeng/components/multiselect/multiselect.js 未找到模块:错误:无法解析 '%projectroot%\node_modules\primeng\components\multiselect' 中的 '@angular/cdk/scrolling'

我还尝试从imports-Array 中删除导入,这导致了不同的错误。我究竟做错了什么?我正在使用 Angular 7 顺便说一句。

删除导入时出现以下错误:

Can't bind to 'options' since it isn't a known property of 'p-dropdown'.
1. If 'p-dropdown' is an Angular component and it has 'options' input, then verify that it is part of this module.
2. If 'p-dropdown' is a Web Component then add 'CUSTOM_ELEMENTS_SCHEMA' to the '@NgModule.schemas' of this component to suppress this message.
3. To allow any property add 'NO_ERRORS_SCHEMA' to the '@NgModule.schemas' of this component. ("
      <p-dropdown [ERROR ->][options]="optionList" [(ngModel)]="selectionString" placeholder="Choose one"></p-dropdown"): ng:///AppModule/ProjectGeneratorComponent.html@13:18
'p-dropdown' is not a known element:
1. If 'p-dropdown' is an Angular component, then verify that it is part of this module.
2. If 'p-dropdown' is a Web Component then add 'CUSTOM_ELEMENTS_SCHEMA' to the '@NgModule.schemas' of this component to suppress this message. ("
      [ERROR ->]<p-dropdown [options]="optionList" [(ngModel)]="selectionString" placeholder="Choose one">"): 

标签: angularprimengprimeng-dropdowns

解决方案


您需要安装 Angular CDK。使用npm install @angular/cdk --save命令。

然后使用在 appModule 中导入多选模块

import {MultiSelectModule} from 'primeng/multiselect';

推荐阅读