通过阅读一些 Angular 资源(见下文),调用模板中的方法可能会导致性能问题。例如
<div>{{getDisplayName()}}</div>
Run Code Online (Sandbox Code Playgroud)
然而,相当多的 Angular Material 库示例调用模板中的方法。
树
https://material.angular.io/components/tree/examples
<mat-icon class="mat-icon-rtl-mirror">
{{treeControl.isExpanded(node) ? 'expand_more' : 'chevron_right'}}
</mat-icon>
Run Code Online (Sandbox Code Playgroud)
带有选择的表
https://material.angular.io/components/table/examples
<td mat-cell *matCellDef="let row">
<mat-checkbox (click)="$event.stopPropagation()"
(change)="$event ? selection.toggle(row) : null"
[checked]="selection.isSelected(row)"
[aria-label]="checkboxLabel(row)">
</mat-checkbox>
</td>
Run Code Online (Sandbox Code Playgroud)
这些方法确实从 Set 中返回一个值。例如 https://github.com/angular/components/blob/4d4ee182de3f306c5fcf49853ef6ac71c4000eea/src/cdk/collections/selection.ts
isSelected(value: T): boolean {
return this._selection.has(value);
}
Run Code Online (Sandbox Code Playgroud)
这些方法会像*普通方法一样导致性能问题吗?或者我缺少什么?
资源