Primeng: p-dropdown doesn't work if the options are read using getter method

Created on 28 Jun 2016  路  5Comments  路  Source: primefaces/primeng

p-dropdown doesn't work if the options are read using getter method

Additional details:

I have a get method like below in my component:
selectedCity= "Paris";
get cities():SelectItem[]{
let cities = [];
cities.push({label:'New York', value:'New York'});
cities.push({label:'Rome', value:'Rome'});
cities.push({label:'London', value:'London'});
cities.push({label:'Istanbul', value:'Istanbul'});
cities.push({label:'Paris', value:'Paris'});
return cities;
}

And in my template i have p-dropdown as

Most helpful comment

I am using the latest version:
Angular: 4.2.4
primeng "^4.1.0-rc.3".

I have the same problem [(ngModel)] not working correctly with p-dropdown.

All 5 comments

I have almost the same problem. If I create a SelectItem array in the construtor and assign this array to the p-dialog, using the attribute or a get method, it works. But if I create the array in the get method, the items in dropdown aren't selectable anymore.

P.S. My p-dropdown is inside a p-dialog.

This do not work:

<p-dropdown [options]="getOptions()" [(ngModel)]="license.licenseStatus" [autoWidth]="false">

options: SelectItem[];

...

getOptions() {
        this.options = [];
        this.options.push({ label: 'Select City', value: null });
        this.options.push({ label: 'New York', value: { id: 1, name: 'New York', code: 'NY'}});
        return this.options;
    }

You guy are both not understanding how [options] is supposed to work here, especially since this is angular. You are meant to bind the options to a variable, for instance, "options" you would, in your constructor set the options variable to the correct value, and in the html it would be [options]="options". In your TS file, is where you construct that variable, and any changes should be automatically replicated to the options of the dropdown (this is just how angular binding works, I have yet to test this). You should not be returning anything to the [options] attribute.

This really should be closed, this ticket is super old.

Please try with the latest PrimeNG version and comment if the issue still persists.

I am using the latest version:
Angular: 4.2.4
primeng "^4.1.0-rc.3".

I have the same problem [(ngModel)] not working correctly with p-dropdown.

With reactive forms its causing a hard to debug issue, if I use a function to get options dropdown will work only on double-click. Do you guys see this as a bug? I can add a demo of this issue if required.

"primeng": "^4.3.0"

Was this page helpful?
0 / 5 - 0 ratings

Related issues

KannanMuruganmony picture KannanMuruganmony  路  3Comments

lilling picture lilling  路  3Comments

papiroca-tm picture papiroca-tm  路  3Comments

Helayxa picture Helayxa  路  3Comments

Helayxa picture Helayxa  路  3Comments