import { Component, ViewEncapsulation, TemplateRef, Input, ContentChild, ElementRef, Renderer2, SimpleChanges, OnChanges } from '@angular/core'; @Component({ selector: 'number-info', template: `
{{_title}}
{{_subTitle}}
{{_total}}{{suffix}} {{_subTotal}}
`, styleUrls: [ './number-info.less' ], encapsulation: ViewEncapsulation.None }) export class NumberInfoComponent implements OnChanges { _title = ''; _titleTpl: TemplateRef; @Input() set title(value: string | TemplateRef) { if (value instanceof TemplateRef) this._titleTpl = value; else this._title = value; } _subTitle = ''; _subTitleTpl: TemplateRef; @Input() set subTitle(value: string | TemplateRef) { if (value instanceof TemplateRef) this._subTitleTpl = value; else this._subTitle = value; } _total = ''; _totalTpl: TemplateRef; @Input() set total(value: string | TemplateRef) { if (value instanceof TemplateRef) this._totalTpl = value; else this._total = value; } _subTotal = ''; _subTotalTpl: TemplateRef; @Input() set subTotal(value: string | TemplateRef) { if (value instanceof TemplateRef) this._subTotalTpl = value; else this._subTotal = value; } @Input() suffix: string; @Input() status: 'up' | 'down'; @Input() theme: 'light' = 'light'; @Input() gap = 8; constructor(private el: ElementRef, private renderer: Renderer2) {} _classMap: string[] = []; setClass() { this._classMap.forEach(cls => this.renderer.removeClass(this.el.nativeElement, cls)); this._classMap = [ `number-info` ]; if (this.theme) this._classMap.push(this.theme); this._classMap.forEach(v => this.renderer.addClass(this.el.nativeElement, v)); } ngOnChanges(changes: SimpleChanges): void { this.setClass(); } }