【问题标题】:Primeng Component UI issuesPrimeng 组件 UI 问题
【发布时间】:2018-03-14 08:24:28
【问题描述】:

我正在研究 PrimeNG 组件。但是我在网络浏览器上的 UI 显示有问题。

现在,我想显示静态下拉菜单。我参考了PrimeNG。以下代码用于显示该组件。

HTML 文件

<h3 class="first">Single</h3>
<p-dropdown [options]="cities" [(ngModel)]="selectedCity" placeholder="Select a City"></p-dropdown>
<p>Selected City: {{selectedCity ? selectedCity.name : 'none'}}</p>

组件文件

import { Component, OnInit } from '@angular/core';
import { SelectItem } from 'primeng/primeng';

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css']
})
export class AppComponent implements OnInit {

  cities: SelectItem[];

  selectedCity: string;
  constructor() {
    this.cities = [];
    this.cities.push({ label: 'Select City', value: null });
    this.cities.push({ label: 'New York', value: { id: 1, name: 'New York', code: 'NY' } });
    this.cities.push({ label: 'Rome', value: { id: 2, name: 'Rome', code: 'RM' } });
    this.cities.push({ label: 'London', value: { id: 3, name: 'London', code: 'LDN' } });
    this.cities.push({ label: 'Istanbul', value: { id: 4, name: 'Istanbul', code: 'IST' } });
    this.cities.push({ label: 'Paris', value: { id: 5, name: 'Paris', code: 'PRS' } });

  }
  ngOnInit() {

  }
}

并且在模块文件中,我已经导入了 -

import { DropdownModule } from 'primeng/primeng';


imports: [
DropdownModule
]

index.html

<link rel="stylesheet" type="text/css" href="assets/stylesheet/bootstrap.min.css">

  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>

  <link rel="stylesheet" type="text/css" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css"

但是当我运行项目时,它并没有向我展示他们在 PrimeNG 下拉示例中所做的事情,而不是让我得到这个结果

谁能指导或帮助我解决我需要进行更改的地方。提前致谢。

【问题讨论】:

  • 你安装了这个库吗?如果没有,请使用“npm install primeng --save”并重试
  • @GiliYaniv 是的,我已经这样做了。
  • 您是如何创建项目的?什么版本的 Angular CLI?
  • @MihirB 您是否在项目中添加了primeng 样式?我认为您没有添加primeng样式。
  • @Chandru nop。我在资产样式表中添加了一个引导 css。而且我还没有添加这种primeng风格。我必须在哪里添加?

标签: angular primeng primeng-dropdowns


【解决方案1】:

试试这样:

npm install primeng​​strong>

npm install primeng --save

在 .angular-cli.json 中添加样式

.angular-cli.json

"styles": [
    "../node_modules/primeng/resources/themes/omega/theme.css",
    "../node_modules/primeng/resources/primeng.min.css"
]

module.ts

import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
import {DropdownModule} from 'primeng/primeng';

@NgModule({
    imports: [
        DropdownModule,
        BrowserAnimationsModule
    ],
})

【讨论】:

  • 好的,这对我有帮助!
猜你喜欢
  • 2021-09-28
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2022-01-10
  • 2016-09-29
  • 2017-07-23
  • 2021-01-28
  • 1970-01-01
相关资源
最近更新 更多