我无法访问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>
在这里演示