*ngfor 中的 ng-modell 未显示正确的值

ng-modell in an *ngfor does not show the right value

我有一个 JSON 已加载到我的 Angular2 应用程序中。

我的 JSON 名为 tempPromotion,我尝试通过以下方式进入 ['results']

tempPromotion['response_payload']['ruleset_list']['results']

['results']中有2个值,['value_path']['calculation']

我的 HTML 看起来像这样:

  <table class="table table-striped">
      <thead>
        <tr>
          <th>Value Path</th>
          <th>Result</th>
          <th>TEST</th>
        </tr>
      </thead>
      <tbody>
        <tr *ngFor="let result of rule['results']; let x = index">
          <td><input type="text" class="form-control" id="valuePath{{x}}" [(ngModel)]="result['value_path']" name="valuePath{{x}}"></td>
          <td><input type="text" class="form-control" id="discount{{x}}" [(ngModel)]="result['calculation']" name="discount{{x}}"></td>
          <td>{{x}} {{result['calculation']}}</td>
        </tr>
      </tbody>
    </table>

为了理解我为什么使用 rule,这已经在另一个 *ngfor <div class="card" *ngFor="let rule of tempPromotion['response_payload']['ruleset_list']; let i = index">

我的输出看起来像这样

channel 1 | #Value * 0.8 | 0 #Value * 0.9 
channel 1 | #Value * 0.8 | 1 #Value * 0.8 

我的 [(ngModel)] 显示了错误的值,而我的双向绑定 {{result['calculation']}} 显示了正确的值。

为什么会发生这种情况,这个问题的解决方案是什么?

我成功了。

我的问题是我的输入有相同的 ID/名称。

id="valuePath{{x}}" 更改为 id="valuePath{{i}}{{x}}" 修复了它。