diff --git a/src/ui-scroll.component.ts b/src/ui-scroll.component.ts index b7d68573..c4fcb810 100644 --- a/src/ui-scroll.component.ts +++ b/src/ui-scroll.component.ts @@ -1,7 +1,8 @@ import { Component, OnInit, OnDestroy, TemplateRef, ElementRef, - ChangeDetectionStrategy, ChangeDetectorRef + ChangeDetectionStrategy, ChangeDetectorRef, + ViewChild } from '@angular/core'; import { Workflow } from './component/workflow'; @@ -9,7 +10,7 @@ import { Datasource as IDatasource } from './component/interfaces/index'; import { Datasource } from './component/classes/datasource'; import { Item } from './component/classes/item'; -const template = ` +const template = `
odd: item.$index % 2, even: !(item.$index % 2) }" ->
` +>
`; /* tslint:disable:component-selector */ @Component({ @@ -45,6 +46,9 @@ const template = ` }) export class UiScrollComponent implements OnInit, OnDestroy { + @ViewChild('uiScrollTemplateRef', { static: true }) + public uiScrollTemplateRef: TemplateRef; + // come from the directive public version: string; public template: TemplateRef; diff --git a/src/ui-scroll.directive.ts b/src/ui-scroll.directive.ts index 8b9766d1..649bbc88 100644 --- a/src/ui-scroll.directive.ts +++ b/src/ui-scroll.directive.ts @@ -26,14 +26,13 @@ export class UiScrollDirective implements OnInit { } ngOnInit() { - const templateView = this.templateRef.createEmbeddedView({}); const compFactory = this.resolver.resolveComponentFactory(UiScrollComponent); - const componentRef = this.viewContainer.createComponent( - compFactory, undefined, this.viewContainer.injector, [templateView.rootNodes] - ); + const componentRef = compFactory.create(this.viewContainer.injector); componentRef.instance.datasource = this.datasource; componentRef.instance.template = this.templateRef; componentRef.instance.isTable = this.isTable; componentRef.instance.version = version; + + this.viewContainer.createEmbeddedView(componentRef.instance.uiScrollTemplateRef); } }