0

I have a couple of arrays and am looping through them to build a table. The first header row is an array of column names and the second a row of select boxes that the user will use to select to map to the above column names

    <h2>CSV Parser</h2>
<div class="alert alert-info" ng-if="helpText">
    {{helpText}}
</div>
<table class="table table-striped table-hover">
    <thead>
        <tr>
            <th ng-repeat="col in data.cols track by $index">{{col}}</th>
        </tr>
        <tr>
            <th ng-repeat="col in data.cols track by $index">
                <select class="form-control"  
                    ng-options="colToMap as colToMatch for colToMatch in colsToMatch" 
                    ng-change="setColMap($index,colToMap)" 
                    ng-model="lastFieldSet[$index]">
                    <option value="">Select Field</option>
                </select>

            </th>
        </tr>
    </thead>
    <tbody>
        <tr ng-repeat="row in data.rows track by $index">
            <td ng-repeat="text in row track by $index">{{text}}</td>
        </tr>
    </tbody>
</table>

When I change any of the selects the change function does not fire at all but if I change it to a click, it fires. At no time does the lastFieldSet[] model get updated.

Any ideas as to what is going on here?

Jared Reeves
  • 1,390
  • 2
  • 15
  • 29
shaneburgess
  • 15,702
  • 15
  • 47
  • 66

2 Answers2

2

according to offcial api document, ng-change only works on input

Evaluate the given expression when the user changes the input.
worldask
  • 1,837
  • 3
  • 22
  • 37
2

To expand on the answer by @worldask:

An ng-change expression is only fired when there is a input value change that results in a new value for the model. It is for this reason why ng-change only works on input. Basically, in your code angular does not know when ngChange should be fired because there is not a value change to the model.

Jared Reeves
  • 1,390
  • 2
  • 15
  • 29
  • hmm, you are on to something here. I did an init on that array and I am a bit further than I was before. Thanks! – shaneburgess Sep 19 '14 at 15:38
  • there is a possible workaround, you could consider implementing a watch that will trigger the same event as what you are trying to do in the change. Note: this would result in the watch firing on any change to the model rather then on the single input change. – Jared Reeves Sep 19 '14 at 15:44