Skip to content

Instantly share code, notes, and snippets.

@ckniffen
Last active May 6, 2016 15:07
Show Gist options
  • Save ckniffen/3020f3cb2d6144c4ed7f41553d598aae to your computer and use it in GitHub Desktop.
Save ckniffen/3020f3cb2d6144c4ed7f41553d598aae to your computer and use it in GitHub Desktop.
import {
Component, Input, DynamicComponentLoader, ElementRef,
ViewContainerRef, ViewChild, Directive
} from 'angular2/core';
import * as _ from 'lodash';
import {FormlyConfig, IFieldConfig} from '../main';
@Directive({
selector: '[child-host]',
})
export class DivComponent {
constructor(public viewContainer:ViewContainerRef){ }
}
@Component({
selector: "formly-field",
template: `
<div child-host #child></div>
`,
providers:[FormlyConfig],
directives: [DivComponent]
})
export class FormlyField {
@Input() model: Object;
@Input() key: string;
@Input() field: IFieldConfig;
@ViewChild(DivComponent) myChild: DivComponent;
constructor(protected elem: ElementRef,
protected fc: FormlyConfig,
protected viewContainer: ViewContainerRef,
protected dcl: DynamicComponentLoader) {
console.log('constructor', this.field);
}
ngAfterViewInit() {
var template = <string>this.field.template
//templateManipulators(preWrapper)
//applyWrappers
//templateManipulators(postWrapper)
@Component({
selector: 'random',
template: template
})
class ChildComponent {
constructor(public formlyField: FormlyField) {}
}
this.dcl.loadNextToLocation(ChildComponent, this.myChild.viewContainer);
}
ngOnInit() {
if(this.field.type) {
let type = this.fc.getType(this.field.type);
_.extend(true, this.field, type);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment