我正在研究 PrimeNG 组件。但是我在 Web 浏览器上的 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>
Run Code Online (Sandbox Code Playgroud)
组件文件
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 …Run Code Online (Sandbox Code Playgroud)