|
6 | 6 | * found in the LICENSE file at https://angular.io/license |
7 | 7 | */ |
8 | 8 |
|
9 | | -import {ɵRenderFlags, ɵbind, ɵcontainer, ɵcontainerRefreshEnd, ɵcontainerRefreshStart, ɵdefineComponent, ɵdetectChanges, ɵelementEnd, ɵelementStart, ɵelementStyleProp, ɵelementStyling, ɵembeddedViewEnd, ɵembeddedViewStart, ɵtext, ɵtextBinding as ɵtextBinding} from '@angular/core'; |
10 | | -import {ComponentDef} from '@angular/core/src/render3/interfaces/definition'; |
| 9 | +import {CommonModule} from '@angular/common'; |
| 10 | +import {Component, Input, NgModule, ɵdetectChanges} from '@angular/core'; |
11 | 11 |
|
12 | 12 | import {TableCell, buildTable, emptyTable} from '../util'; |
13 | 13 |
|
14 | | -const c0 = ['background-color']; |
| 14 | +@Component({ |
| 15 | + selector: 'largetable', |
| 16 | + template: ` |
| 17 | + <table> |
| 18 | + <tbody> |
| 19 | + <tr *ngFor="let row of data; trackBy: trackByIndex"> |
| 20 | + <td *ngFor="let cell of row; trackBy: trackByIndex" [style.background-color]="getColor(cell.row)"> |
| 21 | + {{cell.value}} |
| 22 | + </td> |
| 23 | + </tr> |
| 24 | + </tbody> |
| 25 | + </table> |
| 26 | + `, |
| 27 | +}) |
15 | 28 | export class LargeTableComponent { |
| 29 | + @Input() |
16 | 30 | data: TableCell[][] = emptyTable; |
17 | 31 |
|
18 | | - /** @nocollapse */ |
19 | | - static ngComponentDef: ComponentDef<LargeTableComponent> = ɵdefineComponent({ |
20 | | - type: LargeTableComponent, |
21 | | - selectors: [['largetable']], |
22 | | - consts: 3, |
23 | | - vars: 0, |
24 | | - template: function(rf: ɵRenderFlags, ctx: LargeTableComponent) { |
25 | | - if (rf & ɵRenderFlags.Create) { |
26 | | - ɵelementStart(0, 'table'); |
27 | | - { |
28 | | - ɵelementStart(1, 'tbody'); |
29 | | - { ɵcontainer(2); } |
30 | | - ɵelementEnd(); |
31 | | - } |
32 | | - ɵelementEnd(); |
33 | | - } |
34 | | - if (rf & ɵRenderFlags.Update) { |
35 | | - ɵcontainerRefreshStart(2); |
36 | | - { |
37 | | - for (let row of ctx.data) { |
38 | | - let rf1 = ɵembeddedViewStart(1, 2, 0); |
39 | | - { |
40 | | - if (rf1 & ɵRenderFlags.Create) { |
41 | | - ɵelementStart(0, 'tr'); |
42 | | - ɵcontainer(1); |
43 | | - ɵelementEnd(); |
44 | | - } |
45 | | - if (rf1 & ɵRenderFlags.Update) { |
46 | | - ɵcontainerRefreshStart(1); |
47 | | - { |
48 | | - for (let cell of row) { |
49 | | - let rf2 = ɵembeddedViewStart(2, 2, 1); |
50 | | - { |
51 | | - if (rf2 & ɵRenderFlags.Create) { |
52 | | - ɵelementStart(0, 'td'); |
53 | | - ɵelementStyling(null, c0); |
54 | | - { ɵtext(1); } |
55 | | - ɵelementEnd(); |
56 | | - } |
57 | | - if (rf2 & ɵRenderFlags.Update) { |
58 | | - ɵelementStyleProp(0, 0, null, cell.row % 2 ? '' : 'grey'); |
59 | | - ɵtextBinding(1, ɵbind(cell.value)); |
60 | | - } |
61 | | - } |
62 | | - ɵembeddedViewEnd(); |
63 | | - } |
64 | | - } |
65 | | - ɵcontainerRefreshEnd(); |
66 | | - } |
67 | | - } |
68 | | - ɵembeddedViewEnd(); |
69 | | - } |
70 | | - } |
71 | | - ɵcontainerRefreshEnd(); |
72 | | - } |
73 | | - }, |
74 | | - factory: () => new LargeTableComponent(), |
75 | | - inputs: {data: 'data'} |
76 | | - }); |
| 32 | + trackByIndex(index: number, item: any) { return index; } |
| 33 | + |
| 34 | + getColor(row: number) { return row % 2 ? '' : 'grey'; } |
| 35 | +} |
| 36 | + |
| 37 | +@NgModule({declarations: [LargeTableComponent], imports: [CommonModule]}) |
| 38 | +class TableModule { |
77 | 39 | } |
78 | 40 |
|
| 41 | + |
79 | 42 | export function destroyDom(component: LargeTableComponent) { |
80 | 43 | component.data = emptyTable; |
81 | 44 | ɵdetectChanges(component); |
|
0 commit comments