ng-change不发射但ng-click在ng-repeat中发生

时间:2014-09-19 15:18:47

标签: angularjs angularjs-ng-repeat angularjs-ng-click angularjs-ng-change

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

    <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 []模型都不会更新。

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

2 个答案:

答案 0 :(得分:2)

根据官方api documentng-change仅适用于input

Evaluate the given expression when the user changes the input.

答案 1 :(得分:2)

通过@worldask拓展答案:

仅当输入值更改导致模型的新值时,才会触发ng-change表达式。因此,ng-change仅适用于输入。基本上,在您的代码中,angular不知道何时应该触发ngChange,因为模型没有值更改。