Struggling with a TypeScript if else code that is causing errors when trying to access it. The specific error message being displayed is:
"Cannot read properties of undefined (reading 'setNewsProvider')"
Code Snippet
if (this.newsShow != null) {
if (this.glbNews.nIds == null) {
this.setNewsProvider(); //This works fine
}
else {
if (this.newsShow.EmpLst == null) {
this.setNewsProvider(); // This also works
}
else {
if (this.newsShow.LCL == "X300") {
if (this.newsShow.MXD == "N300") {
var prd1 = this.newsShow.ProducerChk;
this.glbNews.PrdNcc.forEach(function (value) {
if (value == prd1) {
this.setNewsProvider(); // Error occurs here: "Cannot read properties of undefined (reading 'setNewsProvider')"
}
})
}
else {
//Additional code goes here
})
}
}
}
}
}