question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

TypeError: elements.forEach is not a function

See original GitHub issue

Upon 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:closed
  • Created 6 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
natejgardnercommented, Aug 23, 2017

Thanks! That works.

0reactions
emoralesb05commented, Aug 23, 2017

Awesome! Closing this issue 😄

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found