0

我有几个数组,正在循环它们以构建一个表。第一个标题行是列名数组,第二个标题行是用户将用来选择以映射到上述列名的选择框

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

当我更改任何选择时,更改功能根本不会触发,但如果我将其更改为单击,它会触发。lastFieldSet[] 模型在任何时候都不会更新。

关于这里发生了什么的任何想法?

4

2 回答 2

2

根据官方api文档ng-change仅适用于input

Evaluate the given expression when the user changes the input.
于 2014-09-19T15:29:15.570 回答
2

扩展@worldask 的答案:

ng-change 表达式仅在输入值更改导致模型出现新值时才会触发。正是出于这个原因,ng-change 仅适用于输入。基本上,在您的代码中,角度不知道何时应该触发 ngChange,因为模型没有值更改。

于 2014-09-19T15:35:47.977 回答