2 ComponentFactoryResolver,
7 } from '@angular/core';
9 import { AlertPanelComponent } from '../components/alert-panel/alert-panel.component';
10 import { LoadingPanelComponent } from '../components/loading-panel/loading-panel.component';
11 import { LoadingStatus } from '../forms/cd-form';
14 selector: '[cdFormLoading]'
16 export class FormLoadingDirective {
18 private templateRef: TemplateRef<any>,
19 private viewContainer: ViewContainerRef,
20 private componentFactoryResolver: ComponentFactoryResolver
23 @Input('cdFormLoading') set cdFormLoading(condition: LoadingStatus) {
27 this.viewContainer.clear();
30 case LoadingStatus.Loading:
31 factory = this.componentFactoryResolver.resolveComponentFactory(LoadingPanelComponent);
32 content = this.resolveNgContent($localize`Loading form data...`);
33 this.viewContainer.createComponent(factory, null, null, content);
35 case LoadingStatus.Ready:
36 this.viewContainer.createEmbeddedView(this.templateRef);
38 case LoadingStatus.Error:
39 factory = this.componentFactoryResolver.resolveComponentFactory(AlertPanelComponent);
40 content = this.resolveNgContent($localize`Form data could not be loaded.`);
41 const componentRef = this.viewContainer.createComponent(factory, null, null, content);
42 (<AlertPanelComponent>componentRef.instance).type = 'error';
47 resolveNgContent(content: string) {
48 const element = document.createTextNode(content);