【问题标题】:DebugElement.children has a different order than NativeElement.childrenDebugElement.children 的顺序与 NativeElement.children 不同
【发布时间】:2016-11-25 19:26:06
【问题描述】:

我有一个 html 表并想要获取所有行。但是,在 DebugElement 或 NativeElement 上调用 .children 会返回不同的顺序。

我的桌子:

<tbody>
  <tr>
    <td>1</td>
  </tr>
  <tr>
    <td>2</td>
  </tr>
  <tr>
    <td>3</td>
  </tr>
</tbody>

在第一个日志中的 DebugElement 和第二个日志中的 NativeElement 上调用 .children(将它们都转换为数组):

const table: DebugElement = fixture.debugElement.query(By.css('table'));  
console.log(table.query(By.css('tbody')).children.map(e => e.nativeElement));
console.log(Array.from(table.query(By.css('tbody')).nativeElement.children));

第一个记录以下列表:

[
  <tr>
    <td>2</td>
  </tr>,
  <tr>
    <td>1</td>
  </tr>,
  <tr>
    <td>3</td>
  </tr>
]

而第二个记录以下内容:

[
  <tr>
    <td>1</td>
  </tr>,
  <tr>
    <td>2</td>
  </tr>,
  <tr>
    <td>3</td>
  </tr>
]

为什么第一个日志中的顺序被交换了? API 行为有什么不同吗?

【问题讨论】:

    标签: javascript angular angular2-testing


    【解决方案1】:

    这似乎是 Angular 中最近的一个错误:https://github.com/angular/angular/issues/13066

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-02-15
      • 1970-01-01
      • 1970-01-01
      • 2016-07-15
      • 2015-10-17
      • 1970-01-01
      相关资源
      最近更新 更多