Created
September 1, 2019 04:03
-
-
Save chetbis/b3c2a82339a89c8b6acad78cb0fd059e to your computer and use it in GitHub Desktop.
This file contains hidden or 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
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