0

I have a table which has a dropdown above each column where the number of columns is dynamic. I created this as follows

            <table class='table' >
                <tr>
                    <th ng-repeat= "item in importTable[0]">
                        <select ng-model="selectedItem" ng-options="i.Name for i in optionList"></select>
                    </th>
                </tr>
                <tr ng-repeat="row in importTable">
                    <td ng-repeat="item in row">{{ item }} </td>
                </tr>
            </table>

Where optionList is the list of options in the dropdowns. All of the dropdowns have the same optionList.

How do I add the selected item along with the index of the column it is above to the scope to the model?

Here is a link to JSfiddle http://jsfiddle.net/U3pVM/769/ just click import. I want to be able to define which column is which type.

2
  • The column index should then be a property of each item in the array. Post what you are actually trying to do in a fiddle or something. It seems like you are looking for a solution to a solution to a problem that we don't know about. Commented Jun 18, 2013 at 19:51
  • Hi thanks for the reply here is a link. i hope this explains it better! jsfiddle.net/U3pVM/769 Commented Jun 18, 2013 at 20:37

1 Answer 1

1

You may use $index variable that is provided by ngRepeat to set the ngModel to a specific item in an array:

In your controller you first define the array that will hold all the models:

function ImportCtrl($scope) {   
  $scope.selectedItems = [];
  ...
}

And than, inside the ngRepeat you refer your ngModel to a specific item inside the selectedItemsarray:

<select ng-model="selectedItems[$index]" ng-options="i.Name for i in columnNames"></select>

Demo FIDDLE

Sign up to request clarification or add additional context in comments.

Comments

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.