|
@@ -1,5 +1,5 @@
|
|
-import { Component, Input, OnInit } from '@angular/core';
|
|
|
|
-import { ControlContainer } from '@angular/forms';
|
|
|
|
|
|
+import { Component, Input, Optional, OnInit } from '@angular/core';
|
|
|
|
+import { FormGroup, FormGroupName, ControlContainer } from '@angular/forms';
|
|
import { KeysPipe } from '@pipes/keys.pipe';
|
|
import { KeysPipe } from '@pipes/keys.pipe';
|
|
|
|
|
|
@Component({
|
|
@Component({
|
|
@@ -10,6 +10,12 @@ import { KeysPipe } from '@pipes/keys.pipe';
|
|
})
|
|
})
|
|
export class DynaformComponent implements OnInit {
|
|
export class DynaformComponent implements OnInit {
|
|
|
|
|
|
|
|
+ @Input()
|
|
|
|
+ formGroup?: FormGroup;
|
|
|
|
+
|
|
|
|
+ @Input()
|
|
|
|
+ formGroupName?: FormGroupName;
|
|
|
|
+
|
|
@Input()
|
|
@Input()
|
|
set meta(val) {
|
|
set meta(val) {
|
|
this.formMetaData = val;
|
|
this.formMetaData = val;
|
|
@@ -18,15 +24,26 @@ export class DynaformComponent implements OnInit {
|
|
formMetaData: any; // TODO: Tighten up type
|
|
formMetaData: any; // TODO: Tighten up type
|
|
controlNames: Array<string>;
|
|
controlNames: Array<string>;
|
|
|
|
|
|
- constructor(private cc: ControlContainer) {
|
|
|
|
- console.log(this.cc);
|
|
|
|
- }
|
|
|
|
|
|
+ constructor(
|
|
|
|
+ @Optional() private cc: ControlContainer
|
|
|
|
+ ) {}
|
|
|
|
|
|
ngOnInit() {
|
|
ngOnInit() {
|
|
- console.log('dynaform.component ngOnInit');
|
|
|
|
- if (this.cc) {
|
|
|
|
- this.controlNames = Object.keys(this.cc.control.value);
|
|
|
|
|
|
+ console.log('Dynaform Component');
|
|
|
|
+ if (this.formGroup) {
|
|
|
|
+ console.log('Initailised with FormGroup dirtectly: Controls >');
|
|
|
|
+ console.log(Object.keys(this.formGroup.controls));
|
|
|
|
+ }
|
|
|
|
+ if (this.formGroupName) {
|
|
|
|
+ console.log('Initailised with FormGroupName:', this.formGroupName);
|
|
|
|
+ this.formGroup = <FormGroup>this.cc.control; // Get the associated formGroup from the ControlContainer
|
|
|
|
+ console.log('Loading Controls from ControlContainer >');
|
|
|
|
+ console.log(Object.keys(this.formGroup.controls));
|
|
}
|
|
}
|
|
|
|
+ if (!this.formGroup) {
|
|
|
|
+ throw new Error('Dynaform Component Initialised without [formGroup] or formGroupName');
|
|
|
|
+ }
|
|
|
|
+
|
|
}
|
|
}
|
|
|
|
|
|
}
|
|
}
|