首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何访问UI-SELECT下拉值[AngularJS 1.4.7]

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

Stack Overflow用户
提问于 2017-10-19 14:38:32
回答 2查看 850关注 0票数 1

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

代码语言:javascript
复制
<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>

控制器:

代码语言:javascript
复制
$scope.optionType = {};

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

回答 2

Stack Overflow用户

发布于 2017-10-19 14:50:58

检查他们的'Object as source‘example

你需要绑定它来重复,如下所示:

代码语言:javascript
复制
<ui-select-choices repeat="item.type as item in optionTypes">
票数 1
EN

Stack Overflow用户

发布于 2017-10-19 14:58:49

在这里,我认为没有必要通过查看您的dropwon集合来使用ng-bind-html。不过,如果需要的话,请确保在控制器$scope中有trustAsHtml函数,然后使用trustAsHtml(selected.type)而不是ctrl.trustAsHtml(selected.type)

没有 ng-bind-html

代码语言:javascript
复制
<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>
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/46824010

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档