mirror of
https://github.com/angular/angular
synced 2026-05-24 09:28:37 +00:00
37 lines
1.1 KiB
TypeScript
37 lines
1.1 KiB
TypeScript
/**
|
|
* @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.io/license
|
|
*/
|
|
|
|
import {Component, NgModule} from '@angular/core';
|
|
import {BrowserModule, DomSanitizer, SafeStyle} from '@angular/platform-browser';
|
|
|
|
import {emptyTree, TreeNode} from '../util';
|
|
|
|
let trustedEmptyColor: SafeStyle;
|
|
let trustedGreyColor: SafeStyle;
|
|
|
|
@Component({
|
|
selector: 'tree',
|
|
inputs: ['data'],
|
|
template: `<span [style.backgroundColor]="bgColor"> {{ data.value }} </span
|
|
><tree *ngIf="data.right != null" [data]="data.right"></tree
|
|
><tree *ngIf="data.left != null" [data]="data.left"></tree>`,
|
|
})
|
|
export class TreeComponent {
|
|
data: TreeNode = emptyTree;
|
|
get bgColor() {
|
|
return this.data.depth % 2 ? trustedEmptyColor : trustedGreyColor;
|
|
}
|
|
}
|
|
|
|
@NgModule({imports: [BrowserModule], bootstrap: [TreeComponent], declarations: [TreeComponent]})
|
|
export class AppModule {
|
|
constructor(sanitizer: DomSanitizer) {
|
|
trustedEmptyColor = sanitizer.bypassSecurityTrustStyle('');
|
|
trustedGreyColor = sanitizer.bypassSecurityTrustStyle('grey');
|
|
}
|
|
}
|