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

Rüd*_*ger 3 primeng angular primeng-dropdowns

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

npm i primeng --save
Run Code Online (Sandbox Code Playgroud)

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

<p-dropdown [options]="optionList" [(ngModel)]="selectionString" placeholder="Choose one"></p-dropdown>
Run Code Online (Sandbox Code Playgroud)

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

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

我还尝试从imports-Array中删除导入,这导致了另一个错误。我究竟做错了什么?我正在使用Angular 7 btw。

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

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">"): 
Run Code Online (Sandbox Code Playgroud)

Par*_*iya 18

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

然后使用以下命令在appModule中导入多选模块

import {MultiSelectModule} from 'primeng/multiselect';
Run Code Online (Sandbox Code Playgroud)


Sey*_*izi 8

如果你想使用prime NG组件,首先你应该做一些步骤并注意它们已经做得很好。首先,您应该通过代码编辑器中的终端安装软件包。你应该安装这些:

    npm install primeng --save   //install prime in your machine

    npm install primeicons --save    //install prime icon in your machine
Run Code Online (Sandbox Code Playgroud)

下一个:你应该去你的项目中的 angular.json 文件和样式部分,你应该复制这些行。这些行实际上是 node_module 文件夹中库的路径。但是本章中真正重要的是,您使用的是哪个版本的 angular。如果您使用的是 Angular 版本 4 及以下版本,则应将这些路径复制到样式章节:

"../node_modules/primeicons/primeicons.css",
"../node_modules/primeng/resources/themes/nova-light/theme.css",
"../node_modules/primeng/resources/primeng.min.css",
Run Code Online (Sandbox Code Playgroud)

但如果您使用的版本超过 4,则意味着 5 或 6 或 7,您应该复制这些路径:

  "./node_modules/primeicons/primeicons.css",
  "./node_modules/primeng/resources/themes/nova-light/theme.css",
  "./node_modules/primeng/resources/primeng.min.css",
Run Code Online (Sandbox Code Playgroud)

然后你可以去简单地在你的 app.module 中导入 primes 模块并使用 html 标记来呈现组件。但请注意,某些组件需要动画,您应该通过 npm 将其安装在您的机器上。

     npm install @angular/animations --save
Run Code Online (Sandbox Code Playgroud)

并在 app 模块中导入模块:

 import {BrowserAnimationsModule} from '@angular/platform-browser/animations';
Run Code Online (Sandbox Code Playgroud)

我希望它可以帮助你。