簡體   English   中英

如何訪問 UI-SELECT 下拉值 [AngularJS 1.4.7]

[英]How to access UI-SELECT Dropdown value [AngularJS 1.4.7]

我無法在 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"}
  ]

檢查他們的“對象作為源”示例

您需要像這樣綁定它以重復:

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

通過查看您的 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>

演示在這里

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM