@chatterton/angular2-schema-form
Version:
Angular2 Schema Form (DISCLAIMER: it is not related to angular-schema-form)
38 lines (28 loc) • 862 B
text/typescript
import {
Component,
ChangeDetectorRef,
EventEmitter,
Input,
OnInit,
Output,
ViewChild,
ViewContainerRef,
} from '@angular/core';
import { WidgetFactory } from './widgetfactory';
({
selector: 'sf-widget-chooser',
template: `<div #target></div>`,
})
export class WidgetChooserComponent implements OnInit {
() widgetInfo: any;
() widgetInstanciated = new EventEmitter<any>();
('target', {read: ViewContainerRef}) private container: ViewContainerRef;
private widgetInstance: any;
constructor(private widgetFactory: WidgetFactory = null, private cdr: ChangeDetectorRef) {}
ngOnInit() {
let ref = this.widgetFactory.createWidget(this.container, this.widgetInfo.id);
this.widgetInstanciated.emit(ref.instance);
this.widgetInstance = ref.instance;
this.cdr.detectChanges();
}
}