/** * @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} from '@angular/platform-browser'; import {TreeNode, emptyTree, maxDepth} from '../util'; function createTreeComponent(level: number, isLeaf: boolean) { const nextTreeEl = `tree${level+1}`; let template = ` {{data.value}} `; if (!isLeaf) { template += `<${nextTreeEl} [data]='data.right'><${nextTreeEl} [data]='data.left'>`; } @Component({selector: `tree${level}`, template: template}) class TreeComponent { @Input() data: TreeNode; } return TreeComponent; } @Component({selector: 'tree', template: ``}) export class RootTreeComponent { @Input() data: TreeNode = emptyTree; } function createModule(): any { const components: any[] = [RootTreeComponent]; for (let i = 0; i <= maxDepth; i++) { components.push(createTreeComponent(i, i === maxDepth)); } @NgModule({imports: [BrowserModule], bootstrap: [RootTreeComponent], declarations: [components]}) class AppModule { } return AppModule; } export const AppModule = createModule();