TypeError: elements.forEach is not a function
See original GitHub issueUpon creating a basic form:
<td-dynamic-forms [elements]="myElements" #myForm></td-dynamic-forms>
myElements: ITdDynamicElementConfig[] = [{
name: "field",
type: TdDynamicElement.Input,
label: "Field",
default: "Some Field",
required: true
},{...},{...}]
@ViewChild('myForm')
_myForm: TdDynamicFormsComponent;
I get the error
FiltersComponent.html:27 ERROR TypeError: elements.forEach is not a function
at TdDynamicFormsComponent.set [as elements] (dynamic-forms.component.js:38)
at updateProp (core.es5.js:11102)
at checkAndUpdateDirectiveInline (core.es5.js:10794)
at checkAndUpdateNodeInline (core.es5.js:12332)
at checkAndUpdateNode (core.es5.js:12271)
at debugCheckAndUpdateNode (core.es5.js:13132)
at debugCheckDirectivesFn (core.es5.js:13073)
at Object.eval [as updateDirectives] (FiltersComponent.html:33)
at Object.debugUpdateDirectives [as updateDirectives] (core.es5.js:13058)
at checkAndUpdateView (core.es5.js:12238)
The line it’s identifying is the above html.
What’s especially odd is that this issue came up spontaneously. Everything was working fine, I rebuilt, and this happened.
In the debugger, elements starts as an array containing all of my form elements. Looks totally normal. Later, elements becomes a TdDynamicFormsComponent object:
TdDynamicFormsComponent {_formBuilder: FormBuilder, _dynamicFormsService: TdDynamicFormsService, _changeDetectorRef: ViewRef_, dynamicForm: FormGroup}
controls
:
(...)
dynamicForm
:
FormGroup {validator: null, asyncValidator: null, _pristine: true, _touched: false, _onCollectionChange: ƒ, …}
elements
:
(...)
errors
:
(...)
form
:
(...)
valid
:
(...)
value
:
(...)
_changeDetectorRef
:
ViewRef_ {_view: {…}, _viewContainerRef: null, _appRef: null}
_dynamicFormsService
:
TdDynamicFormsService {}
_formBuilder
:
FormBuilder {}
__proto__
:
Object
And this is where it fails. Elements should always be of type ITdDynamicElementConfig[] in my Typescript, but somehow it gets changed.
Issue Analytics
- State:
- Created 6 years ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
forEach is not a function error with JavaScript array
First option: invoke forEach indirectly. The parent.children is an Array like object. Use the following solution: const parent = this.el.
Read more >TypeError: foreach is not a function in JavaScript - Java2Blog
TypeError: .foreach is not a function occurs when we call foreach() function on object which is not array, Set or Map. To resolve...
Read more >TypeError: forEach is not a function in JavaScript - Stack Diary
The "TypeError: forEach is not a function" error is thrown when the code attempts to call the forEach() method on a value that...
Read more >Fix Uncaught TypeError: forEach is not a function Error in ...
The JavaScript “forEach is not a function” error occurs when you call the method 'forEach()' on a variable or property that's not of...
Read more >How to to solve 'TypeError: forEach is not a function' error in ...
The reason why the error happens is that you are trying to call .forEach function on something which is not an array, Map...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

Thanks! That works.
Awesome! Closing this issue 😄