1

I'm unable to access the selected dropdown value in UI-Select, How do I access the selected values in the controller?

<ui-select name="optionType" ng-model="optionType.selected" theme="bootstrap"  append-to-body="true" reset-search-input="true">
  <ui-select-match placeholder="Option">
    <span ng-bind-html="ctrl.trustAsHtml($select.selected.type)"></span>
  </ui-select-match>
  <ui-select-choices repeat="option in optionTypes | filter: $select.search" position="down">
    <span ng-bind-html="ctrl.trustAsHtml(option.type) | highlight: $select.search"></span>
  </ui-select-choices>
</ui-select>

Controller:

$scope.optionType = {};

$scope.optionTypes =
  [
    {type: "Risk Reversal"},
    {type: "Straddle"},
    {type: "Strangle"},
    {type: "Spread"},
    {type: "VANILLA"}
  ]
Ash Rhazaly
  • 205
  • 3
  • 14

2 Answers2

1

Check their 'Object as source' example

You need to bind it to repeat like this:

<ui-select-choices repeat="item.type as item in optionTypes">
Pankaj Parkar
  • 134,766
  • 23
  • 234
  • 299
michal.jakubeczy
  • 8,221
  • 1
  • 59
  • 63
0

There I don't see a need of using ng-bind-html by looking at your dropwon collection. Although if you need it there make sure you have trustAsHtml function, inside your controller $scope and then use trustAsHtml(selected.type) instead of ctrl.trustAsHtml(selected.type).

Without ng-bind-html

<ui-select name="optionType" ng-model="optionType.selected" theme="bootstrap" append-to-body="true" reset-search-input="true">
    <ui-select-match placeholder="Option">
      <span ng-bind="$select.selected.type"></span>
    </ui-select-match>
    <ui-select-choices repeat="option in optionTypes | filter: $select.search" position="down">
      <span ng-bind="option.type | highlight: $select.search"></span>
    </ui-select-choices>
</ui-select>

Demo Here

Pankaj Parkar
  • 134,766
  • 23
  • 234
  • 299