Search code examples
angularngx-bootstrapngx-select-dropdown

How to set default value in ngx-dropdown-list


What i want is on refresh the page i want to get the value from API and add as selected in the select list. Here the syntax

<ngx-dropdown-list (selectionChange)="onChange($event)"
                   [items]="optionItems"
                   [multiSelection]="false"
                   [placeHolder]="'place holder of the drop-down list'"
                   [(selectedValue)]="maxRowsLimitation"
                   [suffixText]="' suffix text'"
                   [filterBox]="false"
                   [formatNumber]="true"
                   [disabled]="false">
</ngx-dropdown-list>

How i can the add the selected value from the list from component ts file?


Solution

  • I have analysis your issue and the solution is to add selected property should be set to true in your object.

    Kindly check this link https://stackblitz.com/edit/angular-ivy-mdpelb?file=src%2Fapp%2Fapp.component.ts

    optionItems = [
      {id: 'Max',     value: 'Max',     text: 'Maximum'},
      {id: 'Average', value: 'Average', text: 'Average'},
      {id: 'Sum',     value: 'Sum',     text: 'Total', selected:true},
      {id: 'Last',    value: 'Last',    text: 'Last'}
    ];