微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

angular – primeng下拉组件错误(‘p-dropdown’不是已知元素)

遵循指南: https://www.primefaces.org/primeng/
我已经尝试按照上面详述的步骤安装PrimeNG以与Angular4一起使用,但是我得到了错误

'p-dropdown' is not a kNown element:

我尝试重建项目,正如其他帖子所建议的那样,但它对我不起作用.任何提示

以下是所有细节:

– PrimeNg安装

npm install primeng --save

– file:testdropdown.component.html

<p-dropdown [options]="cities" [(ngModel)]="selectedCity"></p-dropdown>

– file:testdropdown.component.ts

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

@Component({
  selector: 'app-testdropdown',templateUrl: './testdropdown.component.html',styleUrls: ['./testdropdown.component.css']
})
export class TestdropdownComponent 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' } });
  }

  ngOnInit() {
  }

}

错误

VM1128:185 [CodeLive] HTTP detected: Connecting using WS
zone.js:630 Unhandled Promise rejection: Template parse errors:
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]="cities" [(ngModel)]="selectedCity"></p-dropdown>
"): ng:///AppModule/TestdropdownComponent.html@0:12
'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]="cities" [(ngModel)]="selectedCity"></p-dropdown>

解决方法

在声明组件的模块中导入下拉模块.

import {DropdownModule} from 'primeng/primeng';

@NgModule({
  imports: [
   DropdownModule
  ],declarations: [TestdropdownComponent ]

})
export class myModule { }

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐