在另一个内部的 ng-repeat 中更新模型

update a model in a ng-repeat inside another

我正在让第一个 ng-repeat 循环处理一些数据,另一个 ng-repeat 循环处理其他数据。我在内部 ng-repeat 中添加了 ng-change,它循环一些数据以用 "options/values" 填充 select 元素,ng-change 必须监听 select 元素的变化并调用每次值更改时都会运行,但不会发生。

这里是 html 代码

                    <tr ng-repeat="memo in memos" class="no-animate">
                        <td class="text-center">{{memo.memoStatus | localize:'ar'}}</td>
                        <td class="text-center">
                            {{memo.memoRequiredDate | date: 'yyyy-MM-dd'}}
                            <p ng-hide="memo.memoRequiredDate">----</p>
                        </td>
                        <td class="text-center">
                            <select ng-model="newInfo.selectedConsultantIndex" ng-change="updateConsultant(memo.caseId, newInfo.selectedConsultantIndex)" class="form-control">
                                <option value="">-- المستشارين --</option>
                                <option ng-repeat="consultant in consultants track by $index" value="{{$index}}">{{consultant.firstName}} {{consultant.lastName}}</option>
                            </select>
                        </td>
                        <td class="text-center">{{memo.court[0].name}}</td>
                        <td class="text-center">
                            <p ng-repeat="defendant in memo.defendant">
                                {{defendant.user.firstName}} {{defendant.user.lastName}} - {{defendant.role[defendant.role.length - 1]}}
                            </p>
                        </td>
                        <td class="text-center">
                            <p ng-repeat="client in memo.client">
                                {{client.user.firstName}} {{client.user.lastName}} - {{client.role[client.role.length - 1]}}
                            </p>
                        </td>
                        <td class="text-center">إختبارية</td>
                        <td class="text-center">{{memo.caseNumber}}</td>
                    </tr>

这是JS代码

 $scope.updateConsultant = function(){
    console.log('hello world');
} 

您应该尝试为您的 select 使用 ngOptions : https://docs.angularjs.org/api/ng/directive/ngOptions

尝试使用 watcher 而不是 ng-change

    $scope.$watch('newInfo.selectedConsultantIndex', function() {
      updateConsultant(...)
    });

您可能必须构建一个数组或其他数据结构来支持您用于更改的任何逻辑。

原来问题是由另一个指令 "angular-print printTable" 引起的,该指令创建了一个只有文本值的新 table,然后覆盖了旧的 table.