1

I migrated to PrimeNG 6.1.7 and I've a problem with p-dropdown. This is my code import in app.module (taken from a simple example):

import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { AppComponent } from './app.component';
import { BrowserAnimationsModule} from '@angular/platform-browser/animations'; 
import {DropdownModule} from 'primeng/dropdown'; // include this for dropdown support
@NgModule({
  declarations: [
    AppComponent
  ],
  imports: [
    BrowserModule,
    BrowserAnimationsModule,
    DropdownModule // dropdown support
  ],
  providers: [],
  bootstrap: [AppComponent],
  schemas:
        []

})
export class AppModule { }

In app.component.ts:

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

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

  constructor(){
    this.employes = [
      {label:'Select Employee', value:null},
      {label:'Franc', value:1},
      {label:'Kiran', value:2},
      {label:'John', value:3},
    ];
  }
ngOnInit(){
}
}

And in html I've:

<p-dropdown employes="" ngmodel="" options="" selectedemploye=""></p-dropdown>
Selected Employee: {{selectedEmploye }}

I also installed primeicons e imported it in angular.json:

...
"styles": [
   "src/styles.css",
   "node_modules/primeicons/primeicons.css"
],
...

Dropdown is not correctly showed: enter image description here

Any suggestion? Very thanks...

bigskull
  • 541
  • 2
  • 18
  • 28

3 Answers3

2

the correct html to use the primeng dropdown in that case should be:

<p-dropdown [options]="employes" [(ngModel)]="selectedEmploye"></p-dropdown>

If after that correction the dropdown doesn't look fine, then you have to take a look on how you installed the primeng library and if the styles are configured propertly and imported in your index.html (https://www.primefaces.org/primeng/#/setup)

<link rel="stylesheet" type="text/css" href="/node_modules/primeicons/primeicons.css" />
<link rel="stylesheet" type="text/css" href="/node_modules/primeng/resources/themes/nova-light/theme.css" />
<link rel="stylesheet" type="text/css" href="/node_modules/primeng/resources/primeng.min.css" />
  • Thanks! I imported css files in index.html and now dropdown is correctly showed but clicking on icon dropdown list isn't showed. In F12 inspector i see that div containing list has always display:none... How is possible? – bigskull Nov 28 '18 at 13:43
  • Did you install npm install @angular/animations --save? and add the BrowserAnimationsModule? – Octavio Garbarino Nov 28 '18 at 14:09
  • I solved! There was a custom css file that overrided primeng css... Thanks to Octavio Garbarino! – bigskull Nov 28 '18 at 15:28
  • I am glad that you could found that last issue, and that my answer helps you! You are welcome! – Octavio Garbarino Nov 28 '18 at 15:30
1

I use sass in my angular project and this how I import primeng css files every thing working fine

style.scss

@import "primeicons/primeicons.css";
@import "primeng/resources/themes/nova-dark/theme.css";
@import "primeng/resources/primeng.min.css";

primeicons is different package so make sure to install it npm install primeicons --save

Muhammed Albarmavi
  • 23,240
  • 8
  • 66
  • 91
0

I ran into the same issue. Be sure to add the necessary dependencies via npm install, as well as the browser animation module from angular core. That said, ultimately, what resolved the issue for me was that I had to set a few extra primeNG properties listed in the documentation for autocomplete in my template code, and then I had to override the default primeNG stylings in my scss file.

Listed below is the template code and scss. Obviously, you'll want to customize according to the styling you want, but this worked for me.

PrimeNG autocomplete template code

 <p-autoComplete name="p-autoComplete" [style]="{'width':'100%'}" [inputStyle]="{'width':'100%'}" class="p-autocomplete"
      [suggestions]="listAuthors" (completeMethod)="filterAuthors($event)" [size]="40"
      field= "author" placeholder="Search Quotes" [dropdown]="true" [minLength]="1" [autoHighlight] = "true"
      [dropdown]="true" [autofocus]= "true" [style]="{'text-transform': 'uppercase'}"
      scrollable="true">
  </p-autoComplete>

scss

.ui-autocomplete-dd .ui-autocomplete-dropdown.ui-corner-all{
  position:absolute;
  transform: translateX(-100%);
}

.ui-autocomplete{
  width: 100% !important;
}
  .ui-autocomplete-input{
  width: 100% !important;
}
reverb1010
  • 41
  • 1
  • 8