angular - 尝试在应用程序中使用 PrimeNG 中的 p-Dropdown 时出错

标签 angular primeng primeng-dropdowns

我想使用 this PrimeNG-Dropdown在我的申请中。所以我做了什么:

npm i primeng --save

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

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

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

./node_modules/primeng/components/multiselect/multiselect.js Module not found: Error: Can't resolve '@angular/cdk/scrolling' in '%projectroot%\node_modules\primeng\components\multiselect'

我还尝试从 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">"): 

最佳答案

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

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

import {MultiSelectModule} from 'primeng/multiselect';

关于angular - 尝试在应用程序中使用 PrimeNG 中的 p-Dropdown 时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53888193/

相关文章:

javascript - 最小 Angular2 应用程序接收未处理的 Promise SystemJS 错误

当 Grid 过早换行时(在 11 行而不是 12 行之后)Primeflex Flexgrid 的 CSS 修复?

css - RTL Primeng 下拉组件

angular - PrimeNG 多选自动对焦

angular - Typescript 严格模式无法将 Observable 异步分配给 primeNg 下拉组件

javascript - 是否可以使用 SCSS 将一个元素的 margin-top 设置为另一个元素高度的 60%?

angular - 这个使用 Angularfire2 从 Firebase 数据库中检索列表的示例到底是如何工作的?

angularjs - 如何在模板中绑定(bind)标签p?

angular - 以编程方式在模式弹出窗口中打开 PrimeNG 日历

angular - 如何使用按钮触发primeng colorpicker?