This patch is a final major refactor in styling Angular. This PR includes three main fixes: All temporary state taht is persisted between template style/class application and style/class application in host bindings is now removed. Removes the styling() and stylingApply() instructions. Introduces a "direct apply" mode that is used apply prop-based style/class in the event that there are no map-based bindings as well as property collisions. PR Close #32259 PR Close #32591
43 lines
1.3 KiB
TypeScript
43 lines
1.3 KiB
TypeScript
/**
|
|
* @license
|
|
* Copyright Google Inc. 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.io/license
|
|
*/
|
|
|
|
import {Component, Input, NgModule} from '@angular/core';
|
|
import {BrowserModule, DomSanitizer, SafeStyle} from '@angular/platform-browser';
|
|
|
|
import {TableCell, emptyTable} from '../util';
|
|
|
|
let trustedEmptyColor: SafeStyle;
|
|
let trustedGreyColor: SafeStyle;
|
|
|
|
@Component({
|
|
selector: 'largetable',
|
|
template: `<table><tbody>
|
|
<tr *ngFor="let row of data; trackBy: trackByIndex">
|
|
<td *ngFor="let cell of row; trackBy: trackByIndex" [style.backgroundColor]="getColor(cell.row)">
|
|
{{cell.value}}
|
|
</td>
|
|
</tr>
|
|
</tbody></table>`,
|
|
})
|
|
export class TableComponent {
|
|
@Input()
|
|
data: TableCell[][] = emptyTable;
|
|
|
|
trackByIndex(index: number, item: any) { return index; }
|
|
|
|
getColor(row: number) { return row % 2 ? trustedEmptyColor : trustedGreyColor; }
|
|
}
|
|
|
|
@NgModule({imports: [BrowserModule], bootstrap: [TableComponent], declarations: [TableComponent]})
|
|
export class AppModule {
|
|
constructor(sanitizer: DomSanitizer) {
|
|
trustedEmptyColor = sanitizer.bypassSecurityTrustStyle('white');
|
|
trustedGreyColor = sanitizer.bypassSecurityTrustStyle('grey');
|
|
}
|
|
}
|