【发布时间】:2017-09-06 01:03:06
【问题描述】:
我们有一个数据表组件,它在 IE 11 中的渲染速度很慢。它在 Chrome 中相当不错。但是我们的主浏览器是 IE 11,所以它应该在 IE 11 中运行得很快。
当我在 IE 11 中运行“UI responsive”分析器时,加载或排序表格时最大的问题是 DomEvent。它有很多用于 td、tr 标签的 appendChild、insertBefore 语句,仅这些 DOM 操作就需要大约 8 秒(下面的屏幕截图)。在 Chrome 中大约需要 2 秒,这是可以接受的。
我浏览了一些关于 Angular 1.x 的博客,他们解释了如何优化包含大量条目的表,并在 Angular 2 中尝试了它们,但到目前为止在 IE 11 中没有运气。
我想知道是否有一种方法可以编译所有行并将它们插入在一起,而不是逐行插入。
我创建了一个 plunkr (https://plnkr.co/edit/Wqh6RLwT6IP8ijoIpr4a?p=preview),它还在加载时在 IE 11 分析器报告中显示相同数量的 DOM 事件。
任何其他建议也会有所帮助。
//our root app component
import {Component, NgModule, VERSION} from '@angular/core'
import {BrowserModule} from '@angular/platform-browser'
@Component({
selector: 'my-app',
template: `
<button (click)="loadTable()" class="btn btn-primary">Load</button>
<table class="table">
<tr *ngFor="let item of items">
<td>{{item.id}}</td>
<td>{{item.name}}</td>
</tr>
</table>
`,
})
export class App {
name:string;
items = [];
constructor() {
this.name = `Angular! v${VERSION.full}`;
}
loadTable() {
this.items = this.getItems();
}
private getItems() {
let items = [];
for (let i = 0; i < 5000; i++) {
items.push({ 'id': i, 'name': 'Name' + i })
}
return items;
}
}
@NgModule({
imports: [ BrowserModule ],
declarations: [ App ],
bootstrap: [ App ]
})
export class AppModule {}
【问题讨论】:
-
您是否尝试将 changeDetection 更改为 OnPush?
标签: angular