-
-
Notifications
You must be signed in to change notification settings - Fork 19
/
ui-scroll.directive.ts
39 lines (33 loc) · 1.3 KB
/
ui-scroll.directive.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import { Directive, Input, TemplateRef, ViewContainerRef, ComponentFactoryResolver, OnInit } from '@angular/core';
import version from './ui-scroll.version';
import { UiScrollComponent } from './ui-scroll.component';
import { Datasource } from './component/interfaces/datasource';
@Directive({ selector: '[uiScroll][uiScrollOf]' })
export class UiScrollDirective implements OnInit {
private version: string;
private datasource: Datasource;
private isTable: boolean;
constructor(
private templateRef: TemplateRef<any>,
private viewContainer: ViewContainerRef,
private resolver: ComponentFactoryResolver
) {
}
@Input() set uiScrollOf(datasource: Datasource) {
this.datasource = datasource;
}
@Input() set uiScrollTable(value: any) {
this.isTable = !!value;
}
ngOnInit() {
const templateView = this.templateRef.createEmbeddedView({});
const compFactory = this.resolver.resolveComponentFactory(UiScrollComponent);
const componentRef = this.viewContainer.createComponent(
compFactory, undefined, this.viewContainer.injector, [templateView.rootNodes]
);
componentRef.instance.datasource = this.datasource;
componentRef.instance.template = this.templateRef;
componentRef.instance.isTable = this.isTable;
componentRef.instance.version = version;
}
}