Hi,
i wanted to know if you have an example of how you would code a dropdown with an array of string representing the options.
I would like to avoid to turn this array in a array of object. is it possible ?
Thank you
dropdown with an array of string ?
I just posted this answer at stackoverflow: Getting PrimeNG p-dropdown to work with array of strings is possible, though it is not well documented. I use it sometimes when selecting timezones. There might be cleaner options, but I use ng-template to populate the dropdown and onChange to store the selected string value:
HTML
Component.ts
HTML
Code: Select all
<p-dropdown [options]="portNames" placeholder="Select a Port" (onChange)="storeValue($event)">
<ng-template let-item pTemplate="selectedItem">
{{item}}
</ng-template>
<ng-template let-item pTemplate="item">
{{item}}
</ng-template>
</p-dropdown>
Code: Select all
portNames: string[] =["Port 01","Port 02", "Port 03"];
selectedPort="";
storeValue(event) {
console.log(event); //event.value will likely be undefined, check event.originalEvent
this.selectedPort = event.originalEvent.srcElement.innerText;
}
-
- Information
-
Who is online
Users browsing this forum: No registered users and 20 guests