Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

primeng dropdown component error ('p-dropdown' is not a known element)

Following the guide: https://www.primefaces.org/primeng/ I have tried to install PrimeNG to use with Angular4, following the steps detailed above, but I get the error:

'p-dropdown' is not a known element:

I tried to rebuild the projects, as suggested in other posts, but it did not work for me. Any hints?

Here are all the details:

-- PrimeNg Installation

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() {
  }

}

-- error:

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>
like image 677
Luigi Rubino Avatar asked Jun 02 '17 09:06

Luigi Rubino


People also ask

Can't bind to options since it isn't a known property of dropdown?

Normally, this error occurs when you missed some imports. Please add these line if missing: import { FormsModule, ReactiveFormsModule } from '@angular/forms'; import { DropdownModule } from 'primeng/primeng'; And add them in imports as well.


2 Answers

If still this issue persists, you might have to test one more thing, i.e., if "FormsModule" is imported, if not import it and try,

import { FormsModule } from '@angular/forms';
import { DropdownModule } from 'primeng/primeng';

@NgModule({
  imports: [
    DropdownModule,
    FormsModule
  ],

This should solve the issue.

like image 199
Karthik H Avatar answered Sep 18 '22 18:09

Karthik H


Import the dropdown module in the module where you declare your component.

import {DropdownModule} from 'primeng/primeng';

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

})
export class myModule { }
like image 23
Eduardo Vargas Avatar answered Sep 20 '22 18:09

Eduardo Vargas