0

I am using select, in which I require selected value and dynamically created index (I don't want to set default to [0] index) How it can be done.

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

this is one modal and I want to show these changes of selected mobile in another modal

the second modal consist

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

so in this in the place of [0] index i want to put dynamically selected value.

0

2 Answers 2

1

@Nikhil: First thing ngOptions doesn't support $index like ng-repeat.

If you needed index of that value than you can try like this.

<select 
  ng-model="select"
  ng-options="values.indexOf(selectedItem) as selectedItem for 
selectedItem in values">
</select>
Sign up to request clarification or add additional context in comments.

Comments

0

You can use ng-change and assign value to contact like

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

In controller just set value:

$scope.setNumber = function(num){

$scope.contact = num.value;

}

Then this will show in view

{{contact}}

7 Comments

the second modal consist of ng-repeat so the given value is set to all contacts.
Where you are using ng-repeat.
<ion-item class="item icon-right edit-selection" ng-repeat="contact in modalData" ng-click="selectUserModal(contact)"> <span>{{contact}}</span> <button class="button button-icon ion-ios-close" ng-click="selectUserModal(contact);" ng-class="selectedClassModal(contact)" ng-style="checkSelectedModal(contact)"></button> <button class="button button-icon ion-edit" ng-click="showEditContactModal(contact,$index);" ></button> </ion-item>
oh man then change the variable name I just set as example you can change it.
yes i have changed it, but still have the same problem
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.