angular2-json-schema-form
Version:
Angular 2 JSON Schema Form builder
47 lines (40 loc) • 1.31 kB
text/typescript
import {
Component, ComponentFactoryResolver, ComponentRef, Input,
OnChanges, OnInit, ViewChild, ViewContainerRef
} from '@angular/core';
import { JsonSchemaFormService } from '../library/json-schema-form.service';
export class SelectWidgetComponent implements OnChanges, OnInit {
private newComponent: ComponentRef<any> = null;
formID: number;
layoutNode: any;
layoutIndex: number[];
dataIndex: number[];
private widgetContainer: ViewContainerRef;
constructor(
private componentFactory: ComponentFactoryResolver,
private jsf: JsonSchemaFormService
) { }
ngOnInit() {
this.updateComponent();
}
ngOnChanges() {
this.updateComponent();
}
private updateComponent() {
if (!this.newComponent && this.layoutNode.widget) {
this.newComponent = this.widgetContainer.createComponent(
this.componentFactory.resolveComponentFactory(this.layoutNode.widget)
);
}
if (this.newComponent) {
for (let input of ['formID', 'layoutNode', 'layoutIndex', 'dataIndex']) {
this.newComponent.instance[input] = this[input];
}
}
}
}