From 86be8e46b1e0cec84677293d14d3e7d8b3346330 Mon Sep 17 00:00:00 2001 From: Mark Dinh Date: Thu, 27 Feb 2020 16:31:51 +0000 Subject: [PATCH] Explicitly invoke change detection after dynamically creating component and inputting values. --- src/ui-scroll.component.ts | 4 +--- src/ui-scroll.directive.ts | 1 + 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/src/ui-scroll.component.ts b/src/ui-scroll.component.ts index c5ccda8e..3bb4cfc8 100644 --- a/src/ui-scroll.component.ts +++ b/src/ui-scroll.component.ts @@ -81,9 +81,7 @@ export class UiScrollComponent implements OnInit, OnDestroy { constructor( public changeDetector: ChangeDetectorRef, public elementRef: ElementRef - ) { - setTimeout(() => this.ngOnInit()); // 😢 - } + ) { } ngOnInit() { this.workflow = new Workflow( diff --git a/src/ui-scroll.directive.ts b/src/ui-scroll.directive.ts index 60a58362..f51ceba6 100644 --- a/src/ui-scroll.directive.ts +++ b/src/ui-scroll.directive.ts @@ -34,5 +34,6 @@ export class UiScrollDirective implements OnInit { componentRef.instance.version = version; componentRef.instance.parentElement = this.templateRef.elementRef.nativeElement.parentElement; this.viewContainer.createEmbeddedView(componentRef.instance.uiScrollTemplateRef); + componentRef.changeDetectorRef.detectChanges(); } }