2014-09-04 81 views
0

我在那裏我用NG-重複生成選項的選擇框,但我想,用NG選項角JS選擇NG選項,而不是NG重複

<select ng-change="onChangeShippingMethod(shippingMethodId)" ng-model="shippingMethodId" class="input-full-w normal_dropDown" name="gjh" id="select_shipping_method" > 
    <option ng-repeat="shippingDetail in shipModeArr" value="{{shippingDetail.shipModeId}}" ng-selected="shippingDetail.shipModeId == selectedAddressPerItem[cartItems[0].cartItemId].shipModeId"> 
     {{shippingDetail.description}}&nbsp;Arrives {{shippingDetail.estArrivalDate | changeDateFormat | date:'mediumDate'}}{{shippingDetail.shipCharge | currency}} 
    </option> 
</select> 

中產生,我想一個應根據某些條件選擇特定選項。

,並使用NG-重複一個空的選項與其他選項來

fiddle

+0

那麼,你有什麼嘗試嗎?什麼地方出了錯? – Yoshi 2014-09-04 07:45:05

+0

@yoshi如果我用ng重複一個空選項來與其他選項 – sameer 2014-09-04 08:04:28

+0

@yoshi和選項文本我附加了很多值我怎麼能用ng選項 – sameer 2014-09-04 08:08:02

回答

0

這就是我想到的。下次你真的應該爲你提供一些數據。

爲納克選項有趣的部分是列表解析般的風格在

ng-options="sD.shipModeId as sD.description for sD in shipModeArr" 

編輯:

ng-options="sD.shipModeId as format(sD) for sD in shipModeArr" 

在控制器:

$scope.format = function(sd){ 
    return sd.description 
    + ' Arrives ' 
    + sd.estArrivalDate + ' ' 
    + $filter('currency')(sd.shipCharge); 
}; 

您可以自行定義函數讓你的對象格式很好。我編輯了這個笨蛋,告訴你在哪裏放置這些作品。如果你展開$ scope.format函數來返回你的格式,這應該工作。

如果你不想要一個空的選擇,你將不得不選擇一個初始值。

EDIT2:

我更新了fiddle

plnkr

+0

我要'{{shippingDetail.description}}  抵達{{shippingDetail.estArrivalDate | changeDateFormat |日期:'mediumDate'}} {{shippingDetail.shipCharge |貨幣}}'在選項文本中不僅描述 – sameer 2014-09-04 08:14:46

+0

非常感謝@Christoph Hegemann – sameer 2014-09-04 09:04:15

1

檢查這將是巨大的,如果你提供了一些數據,那麼有人會開發搗鼓它吧我只是可以給你語法試試這個適用於你的代碼。

<select class="form-control" ng-model="searchState" ng-options="st.state for st in stateList | filter:searchCountry | orderBy:'state'"> 
<option value="">Select State</option> 

在這裏我有在ng選項的jsfiddle示例演示。 fiddle對於特定的條件來滿足請在下面的問題中提及那些或使用過濾器,因爲我在上面的代碼中顯示。請以更詳細的格式列出您的問題。包括數據,app.js代碼和一些html。祝你好運。