'this' is undefined inside the foreach loop

后端 未结 3 1813
太阳男子
太阳男子 2020-12-28 12:19

I am writing some typescript code and iterating an array. Inside the loop, I am trying to access \'this\' object to do some processing as:

console.log(\'befo         


        
3条回答
  •  太阳男子
    2020-12-28 12:42

    Try this:

    myarray.days.forEach( (obj) => {
        console.log('before transform, this : ' + this);
        this.datePipe.transform...
    });
    

提交回复
热议问题