Angularのパフォーマンス
*ngFor with Ionic Components
Ionic コンポーネントで*ngForを使用する場合、Angular のtrackByオプションを利用することをお勧めします。これにより、Angular は変更の伝播をより効率的に処理できます。また、コンポーネント全体を再構築するのではなく、コンポーネント内の内容のみを更新することができます。
trackBy でループ内の各要素に安定した識別子を与えると、Angular が要素の挿入や削除を追跡できます。次に trackBy の使用例を示します。
home.page.html
<ion-item *ngFor="let item of items; trackBy:trackItems">
<ion-label>{{ item.value }}</ion-label>
</ion-item>
home.component.ts
items = [
{ id: 0, value: 'Item 0' },
{ id: 1, value: 'Item 1' },
...
]
trackItems(index: number, itemObject: any) {
return itemObject.id;
}
この例では、itemsという名前のオブジェクトの配列があります。各オブジェクトには、valueとidという 2 つのプロパティがあります。trackByを使うことで、各オブジェクトのidを返すtrackItems関数を渡します。このidは、各要素に対して一意な識別子として使用されます。
詳細については、Angular NgForOf の変更伝播に関するドキュメントを参照してください。
From the Ionic Team
How to Lazy Load in Ionic Angular
Improved Perceived Performance with Skeleton Screens
From the Angular Team
Build performant and progressive Angular apps - web.dev
From the Community
High Performance Animations in Ionic - Josh Morony
High Performance List Filtering in Ionic - Josh Morony
Increasing Performance with Efficient DOM Writes in Ionic - Josh Morony
Ionic Framework is Fast (But Your Code Might Not Be) - Josh Morony
共有したいガイドがありますか? 下の Edit this page ボタンをクリックしてください。