Getting values of multiple select inside one ng-repeat
Asked Answered
W

1

6

I have a dropdown in one of my div, from which I am selecting the number of dropdowns to be in second div. My task is to be able to select the different values from each of the dropdowns inside the second div. Here is the code I am trying

<div ng-repeat="i in getNumber(secondN2.core.r1r2.value) track by $index">
                <div>
                    <strong><u>For Core link number {{$index+1}}:</u> </strong><br>
                        <strong>Select IM</strong>
                        <select ng-model="im" ng-change="calculate()" >
                            <option value="1 Gig" selected="selected">1 Gig</option>
                            <option value="10 Gig">10 Gig</option>
                        </select><br>

                </div>

</div>

secondN2.core.r1r2.value is a number, I am converting it to array,a collection, by returning new Array(n), in the getNumber method

How to give the proper ng-model in this case? And how to retrieve the values?

If I try to give i.im, it still does not help. With im, $scope.im is coming undefined

Updated

What is two nested loops are there

<div ng-repeat="j in secondN3.core" style="border:1px solid;">
    <strong>Configure Core Links between {{j.name}}</strong><br><br>
            <div ng-repeat="i in getNumber(j.value) track by $index">
            <div>
                <strong><u>For Core link number {{$index+1}}:</u> </strong><br>
                <strong>Select IM</strong>
                <select ng-model="secondN3.coreValues[[$parent.$index,$index]]" ng-change="calculate()" >
                    <option value="1 Gig" selected="selected">1 Gig</option>
                    <option value="10 Gig">10 Gig</option>
                </select><br>
            </div>
        </div>
<div>

Edit:2

This is working: This is the plunker for that

Wherein answered 28/2, 2015 at 17:5 Comment(0)
I
10

You could have an array in your controller that will hold the selected values:

$scope.values = [];

and then bind your dropdowns to this model:

<select ng-model="values[i]" ng-change="calculate()">
    <option value="1 Gig" selected="selected">1 Gig</option>
    <option value="10 Gig">10 Gig</option>
</select>
Inhospitality answered 28/2, 2015 at 17:13 Comment(1)
I did ng-model="values[$index]", and now it is working :) ThanksWherein

© 2022 - 2024 — McMap. All rights reserved.