Skip to content

Instantly share code, notes, and snippets.

@chetbis
Created September 1, 2019 04:03
Show Gist options
  • Save chetbis/b3c2a82339a89c8b6acad78cb0fd059e to your computer and use it in GitHub Desktop.
Save chetbis/b3c2a82339a89c8b6acad78cb0fd059e to your computer and use it in GitHub Desktop.
class MyClass {
constructor(private readonly fb: FormBuilder) { }
/**
* @desc makes an form array out of deeply nested array of objects
*/
foo(arr = []) {
return arr.map((val) => {
const newVal = JSON.parse(JSON.stringify(val));
Object.keys(newVal).forEach((key) => {
const keyVal = newVal(key);
newVal[key] = Array.isArray(keyVal) ?
this.fb.array(this.foo(keyVal)) : (typeof(keyVal) === 'object' ? this.fb.group(keyVal) : keyVal);
});
return newVal;
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment