/
githubmirror
/
angular
Обзор
Документация
Войти
/
githubmirror
/
angular
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
modules/benchmarks/src/largetable/ng2/table.ts
46 строк
1 KB
Matthieu Riegler
feat(core): Set default Component changeDetection strategy to OnPush
25 мар 2026, 02:25
25 мар 2026, 02:25
eae8f7e
Код
Авторство
О чём код?
/** * @license * Copyright Google LLC All Rights Reserved. * * Use of this source code is governed by an MIT-style license that can be * found in the LICENSE file at https://angular.dev/license */ import {ChangeDetectionStrategy, Component, inject, Input} from '@angular/core'; import {DomSanitizer, SafeStyle} from '@angular/platform-browser'; import {emptyTable, TableCell} from '../util'; let trustedEmptyColor: SafeStyle | null = null; let trustedGreyColor: SafeStyle | null = null; @Component({ selector: 'largetable', template: `<table> <tbody> @for (row of data; track $index) { <tr> @for (cell of row; track $index) { <td [style.backgroundColor]="getColor(cell.row)">{{ cell.value }}</td> } </tr> } </tbody> </table>`, changeDetection: ChangeDetectionStrategy.Eager, }) export class TableComponent { @Input() data: TableCell[][] = emptyTable; constructor() { if (trustedEmptyColor === null) { const sanitizer = inject(DomSanitizer); trustedEmptyColor = sanitizer.bypassSecurityTrustStyle('white'); trustedGreyColor = sanitizer.bypassSecurityTrustStyle('grey'); } } getColor(row: number) { return row % 2 ? trustedEmptyColor : trustedGreyColor; } }