如何访问UI-SELECT下拉值[AngularJS 1.4.7]

时间:2017-10-19 06:38:32

标签: javascript angularjs ui-select angular-ui-select

我无法在UI-Select中访问所选的下拉列表值,如何访问控制器中的选定值?

<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>

控制器:

$scope.optionType = {};

$scope.optionTypes =
  [
    {type: "Risk Reversal"},
    {type: "Straddle"},
    {type: "Strangle"},
    {type: "Spread"},
    {type: "VANILLA"}
  ]

2 个答案:

答案 0 :(得分:1)

检查他们的'对象为来源'example

您需要将其绑定为重复,如下所示:

<ui-select-choices repeat="item.type as item in optionTypes">

答案 1 :(得分:0)

通过查看您的dropwon集合,我看不出需要使用ng-bind-html。如果您需要它,请确保您在控制器trustAsHtml内有$scope功能,然后使用trustAsHtml(selected.type)代替ctrl.trustAsHtml(selected.type)

没有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