我正在研究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下拉示例中所做的事情,而不是在获得此结果时
任何人都可以指导或帮助我解决我需要做哪些更改的问题。提前谢谢。
答案 0 :(得分:3)
试试这样:
npm install primeng
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
],
})