Angular,PrimeNG-p下拉意外显示

时间:2019-06-29 23:20:55

标签: javascript angular primeng

我在Angular应用程序中使用PrimeNG。我打算使用p-dropdown组件,但它在我的组件中呈现的非常奇怪。

p-dropdown strange render

这看起来不像他们在文档中展示的那样。

这是package.json。 (也许Bootstrap和PrimeNG版本未对齐或类似?):

{
  "name": "soar",
  "version": "0.0.0",
  "scripts": {
    "ng": "ng",
    "start": "ng serve",
    "build": "ng build",
    "test": "ng test",
    "lint": "ng lint",
    "e2e": "ng e2e"
  },
  "private": true,
  "dependencies": {
    "@angular/animations": "^7.2.15",
    "@angular/cdk": "^8.0.1",
    "@angular/common": "~7.2.0",
    "@angular/compiler": "~7.2.0",
    "@angular/core": "^8.0.2",
    "@angular/forms": "~7.2.0",
    "@angular/material": "^8.0.1",
    "@angular/platform-browser": "~7.2.0",
    "@angular/platform-browser-dynamic": "~7.2.0",
    "@angular/router": "~7.2.0",
    "@ng-bootstrap/ng-bootstrap": "^4.1.3",
    "@ngrx/effects": "^7.4.0",
    "@ngrx/store": "^7.4.0",
    "@ngrx/store-devtools": "^7.4.0",
    "bootstrap": "^4.3.1",
    "chart.js": "^2.8.0",
    "core-js": "^2.5.4",
    "font-awesome": "^4.7.0",
    "primeng": "^8.0.0",
    "quill": "^1.3.6",
    "rxjs": "~6.3.3",
    "tslib": "^1.9.0",
    "zone.js": "~0.8.26"
  },
  "devDependencies": {
    "@angular-devkit/build-angular": "~0.13.0",
    "@angular/cli": "~7.3.9",
    "@angular/compiler-cli": "~7.2.0",
    "@angular/language-service": "~7.2.0",
    "@ngrx/schematics": "^7.4.0",
    "@types/jasmine": "~2.8.8",
    "@types/jasminewd2": "~2.0.3",
    "@types/node": "~8.9.4",
    "codelyzer": "~4.5.0",
    "jasmine-core": "~2.99.1",
    "jasmine-spec-reporter": "~4.2.1",
    "karma": "~4.0.0",
    "karma-chrome-launcher": "~2.2.0",
    "karma-coverage-istanbul-reporter": "~2.0.1",
    "karma-jasmine": "~1.1.2",
    "karma-jasmine-html-reporter": "^0.2.2",
    "protractor": "~5.4.0",
    "ts-node": "~7.0.0",
    "tslint": "~5.11.0",
    "typescript": "~3.2.2"
  }
}

这是标记:

 <form [formGroup]="registerForm">
    <div class="form-group">
      <p-dropdown [options]="productionSelectItems" formControlName="productionId"></p-dropdown>
    </div>
</form>

我在整个应用程序中使用Bootstrap,但我不会想象这会是一个问题。全披露:我不是UI / UX使用者,但我认为应该将其呈现为某种select元素。可能是什么原因导致的,我该如何解决?

数据不是问题。 Hello World!这是我已经硬编码的一个SelectItem。它的值为1,标签为Hello World!

1 个答案:

答案 0 :(得分:2)

我通过将PrimeNG和Primeicons样式导入到项目的styles.scss文件中来解决了这个问题:

@import "~primeng/resources/primeng.min.css"; 
@import "~primeicons/primeicons.css";

完成此操作后,该下拉列表看起来与PrimeNG文档中的演示类似:

p-dropdown with imported styles