2016-11-25 9 views
3

私はhtmlテーブルを持っていて、すべての行を取得したいと思います。しかし、DebugElementまたはNativeElementで.childrenを呼び出すと、異なる順序が返されます。DebugElement.childrenはNativeElement.childrenと異なる順序を持っています

マイテーブル:

最初のログと第二ログにNativeElementにDebugElementに .childrenを呼び出す
<tbody> 
    <tr> 
    <td>1</td> 
    </tr> 
    <tr> 
    <td>2</td> 
    </tr> 
    <tr> 
    <td>3</td> 
    </tr> 
</tbody> 

(アレイにそれらの両方を変換):

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の動作に違いはありますか?

答えて

関連する問題