Last active
May 6, 2016 15:07
-
-
Save ckniffen/3020f3cb2d6144c4ed7f41553d598aae to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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