Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular2/PrimeNG - Cant display Dropdown

I'm using PrimeNG & Angular2 for my app.

I've got a component which should show a dropdown menu of selectable themes. I've followed the PrimeNG Dropdown documentation and as far as I can see I've got everything build up the same way. But I'm always getting the Error "No value accessor for '' "

theme.component.ts:

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

@Component({
   selector: 'my-themes',
   templateUrl: 'dist/html/theme.component.html',
   directives: [Dropdown],
})


export class ThemeComponent {
   selectables: SelectItem[];
   style: string;

   constructor() {
      this.selectables = [];
      this.selectables.push({ label: 'Nightflat', value: 'Nightflat' });
      this.selectables.push({ label: 'Flat', value: 'Flat' });
   }
   ngOnInit() {

   }

}

theme.component.html:

<p-dropdown [options]="selectables" [(ngModel)]="style"></p-dropdown>

Any ideas where the problem might be? :( Edit: The problem actuallyy is ngModel. The Dropdown gets displayed if I remove it from the html tag.

like image 708
Faigjaz Avatar asked Jul 21 '16 07:07

Faigjaz


1 Answers

There are many similar issues are there have a look here

  • https://github.com/primefaces/primeng/issues/549
  • ngModel: No value accessor for ''

also you can avoid your error message by just changing your ngModel with model but there is current issue with primeng which is being processed.

also try using depracted forms disable.

import { disableDeprecatedForms, provideForms } from '@angular/forms';

bootstrap(AppComponent, [
disableDeprecatedForms(),
provideForms()]);

update

according to officials of primeng problem has been resolved see here.

  • http://forum.primefaces.org/viewtopic.php?f=35&t=46238
like image 188
Pardeep Jain Avatar answered Oct 06 '22 18:10

Pardeep Jain