model-form
Version:
Dynamic Form Builder for Anuglar 5 and the WAR Framework
50 lines • 1.87 kB
JavaScript
import { ComponentFactoryResolver, Directive, Input, ViewContainerRef } from '@angular/core';
import { FormGroup } from '@angular/forms';
/** Form Fields **/
import { InputComponent } from './fields/input.component';
import { EmailComponent } from './fields/email.component';
import { NumberComponent } from './fields/number.component';
import { SwitchComponent } from './fields/switch.component';
import { TextComponent } from './fields/text.component';
var components = {
string: InputComponent,
text: TextComponent,
integer: NumberComponent,
date: InputComponent,
array: InputComponent,
bool: SwitchComponent,
email: EmailComponent,
json: TextComponent
};
var ModelFieldDirective = (function () {
function ModelFieldDirective(resolver, container) {
this.resolver = resolver;
this.container = container;
}
ModelFieldDirective.prototype.ngOnInit = function () {
var comp = components[this.map.type];
var factory = this.resolver.resolveComponentFactory(comp);
this.component = this.container.createComponent(factory);
this.component.instance.map = this.map;
this.component.instance.model = this.model;
this.component.instance.group = this.group;
};
ModelFieldDirective.decorators = [
{ type: Directive, args: [{
selector: '[modelField]'
},] },
];
/** @nocollapse */
ModelFieldDirective.ctorParameters = function () { return [
{ type: ComponentFactoryResolver, },
{ type: ViewContainerRef, },
]; };
ModelFieldDirective.propDecorators = {
"map": [{ type: Input },],
"model": [{ type: Input },],
"group": [{ type: Input },],
};
return ModelFieldDirective;
}());
export { ModelFieldDirective };
//# sourceMappingURL=model-field.directive.js.map