2017-10-19 81 views
1

我無法訪問UI-Select中選定的下拉值,如何訪問控制器中的選定值?如何訪問UI-SELECT下拉值[AngularJS 1.4.7]

<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"} 
    ] 

回答

1

檢查他們的 '對象源' example

您需要將其綁定到重複這樣的:

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

如何在控制器訪問選擇的值有關係嗎? –

+0

通過ng-model,你會得到整個選定的對象 – jabko87

+0

你有一個工作的笨蛋嗎?我沒有定義,當我console.log(「optionType.selected」) –

0

在那裏,我不通過查看你的dropwon系列看到需要使用ng-bind-html。雖然如果您需要它,請確保您的控制器$scope內有trustAsHtml功能,然後使用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