gp-crm-ui
Version:
Модуль компонентов UI Имя модуля: `gp-crm-ui`
83 lines (67 loc) • 2.2 kB
text/typescript
import {
Component,
ComponentFactoryResolver,
ComponentRef,
EventEmitter,
Input,
OnChanges,
OnInit,
SimpleChanges,
ViewChild
} from '@angular/core';
// Директивы
import { CrmViewContainerDirective } from '../../directives';
// Ячейка таблицы
export class CrmTableCellComponent implements OnInit, OnChanges {
constructor(private readonly factoryResolver: ComponentFactoryResolver) {}
// Компонент ячейки
public is: any;
// Данные ячейки
public data: any;
// Столбец
public column: any;
// Строка
public row: any;
// Событие изменения высоты ячейки
public emitterChangeHeight: EventEmitter<any>;
// Ссылка на директиву для доступа к viewContainerRef
public view: CrmViewContainerDirective;
// Ссылка на компонент
private componentRef: ComponentRef<any>;
// Загрузка компонента
private loadComponent(): void {
const factory = this.factoryResolver.resolveComponentFactory(this.is);
const viewContainerRef = this.view.viewContainerRef;
if (viewContainerRef) {
viewContainerRef.clear();
this.componentRef = viewContainerRef.createComponent(factory);
const instance = this.componentRef.instance as {
data: any;
column: any;
row: any;
emitterChangeHeight: EventEmitter<any>;
};
instance.data = this.data;
instance.column = this.column;
instance.row = this.row;
instance.emitterChangeHeight = this.emitterChangeHeight;
}
}
// --------------------------------------------------------------------------
// HOOKS
// Инициализация
public ngOnInit(): void {
this.loadComponent();
}
// Изменение входных параметров
public ngOnChanges(changes: SimpleChanges): void {
if (changes.data && this.componentRef && this.componentRef.instance) {
this.componentRef.instance.data = this.data;
}
}
}