2017-09-29 29 views
0

我使用的選擇,在我需要選擇價值和動態創建的索引(我不想設置默認爲[0]指數) 如何它可以得到選擇價值指數做完了。如何動態地使用angularjs NG選項

 <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> 

這是一個模式,我想在另一個模式

第二模式,顯示選擇移動的這些變化編組

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

所以在的地方[0]索引我想把動態選擇的值。

回答

0

@Nikhil:第一件事ngOptions不支持$指數像NG-重複。

如果您需要的值的指數比你可以嘗試這樣的。

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

可以使用NG-變化和賦值像

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

在控制器剛剛設置值聯繫:

$scope.setNumber = function(num){ 

$ scope.contact = num.value;

}

,那麼這將在視圖顯示

{{contact}} 
+0

第二模態由NG-重複的,從而給定的值被設置爲所有聯繫人。 –

+0

你在哪裏使用ng-repeat。 {{contact}}

+0

<按鈕按鈕圖標ion-ios-close「ng-click =」selectUserModal(contact);「納克級= 「selectedClassModal(接觸)」 NG式= 「checkSelectedModal(接觸)」> <按鈕類= 「按鈕按鈕圖標離子編輯」 NG單擊= 「showEditContactModal(接觸,$指數);」 > –