Property 'forEach' does not exist on type 'NodeList'

2.1k Views Asked by At

I am using ng2-dragula for Drag and Drop in my Table.

  this.dragulaService.drop.subscribe(value => {     

  let questions_group = value[3] as HTMLTableRowElement        
  let SectionTwo:Array<string> = [];
  let QuestionId:Array<string> = [];
  let OrderNo:Array<number> = [];
  var list2 = questions_group.childNodes;      

  list2.forEach( 
    function(currentValue, currentIndex,listObj) { 

      if(currentIndex!=0){           
        let sectionName2 = currentValue.lastChild.textContent
        SectionTwo.push(sectionName2)
        QuestionId.push(currentValue.firstChild.textContent)
        OrderNo.push(currentIndex)

      }         
    },
    ''
  );   });

All of sudden it has started giving me error that "Property 'forEach' does not exist on type 'NodeList'.". Prior it was working fine I didn't do any changes.

2

There are 2 best solutions below

0
On BEST ANSWER

I added property "dom.iterable" in lib in tsconfig.json and it worked

0
On

Another way:

  • Using Spread Operator:

    var list2 = [...questions_group.childNodes]; // Take a look of the syntax
    
    list2.forEach(function(currentValue, currentIndex,listObj) => {
       // Todo
    })