2017-09-29 4 views
0

選択した値と動的に作成されるインデックスが必要なselectを使用しています(デフォルトは[0]インデックスに設定したくありません) 終わり。anglejsでng-optionsを使用して選択した値インデックスを動的に取得する方法

 <div class="input-label"> 
      Select Mobile 
     </div> 

     <select ng-model="mobile" ng-options="mobile as mobile.value for mobile in editContactModalData.phoneNumbers"></select> 
     </label> 

    Above is select option and below is input box where the selected value is set  


     <label class="item item-input item-stacked-label" ng-show="mobile"> 
     <input type="tel" maxlength="10" placeholder="mobile" ng-model="mobile.value"> 
     </label> 

これは1つのモーダルで、私は2番目のモーダルの代わりに、この中にそう

<span>{{contact.phoneNumbers[0].value}}</span> 

から成る別のモーダル

に選択された移動のこれらの変更を表示したいです[0] index私は動的に選択された値を入れたい。

答えて

0

@Nikhil:ngOptionsはng-repeatのように$ indexをサポートしていません。

この値のインデックスが必要な場合は、このように試すことができます。あなたはngの変更を使用して、コントローラだけで設定した値で

<select ng-change="setNumber(mobile)" ng-model="mobile" ng-options="mobile as mobile.value for mobile in editContactModalData.phoneNumbers"></select> 

のように連絡して値を割り当てることができ

<select 
    ng-model="select" 
    ng-options="values.indexOf(selectedItem) as selectedItem for 
selectedItem in values"> 
</select> 
0

$scope.setNumber = function(num){ 

$ scope.contact = num.value。

}

は、この指定された値がすべての連絡先に設定されているよう

{{contact}} 
+0

第モーダルがNGリピートから成るビューに表示されます。 –

+0

ng-repeatを使用している場所。 –

+0

<アイテムアイテムクラス= "アイテムアイコン - 右側の編集選択" ng-repeat = "連絡先をmodalDataで" ng-click = "selectUserModal(連絡先)"> {{連絡先}}

関連する問題