Я пытаюсь установить setTimeout внутри переключателя, внутри foreach, внутри функции ...
TypeError: undefined не является объектом (оценивается this.ata)
Я пытался
import { DataProvider } from '../xml-provider';
constructor(private Data: DataProvider) { }
items = this.Data.xmldata['step']; //XML turned into array using
initiateStepActions(){
var actionsToTake = this.items[this.currentStep]['timed_actions'];
if (actionsToTake){
this.items[this.currentStep]['timed_actions'][0]['action'].forEach(function(foundAction){
switch (type) {
case 'customerchat':
var MesgObject = {text : foundAction['_']};
//setTimeout(() => {this.Data.broadcastCustomerChatMesg(MesgObject)}, Number(foundAction['$']['showAtSecond']));
//setTimeout (() => this.Data.broadcastCustomerChatMesg(MesgObject), Number(foundAction['$']['showAtSecond']));
//setTimeout ( (this.Data.broadcastCustomerChatMesg(MesgObject)).bind(this), Number(foundAction['$']['showAtSecond']));
//setTimeout (this.Data.broadcastCustomerChatMesg(MesgObject), Number(foundAction['$']['showAtSecond']));
setTimeout (function(this) { this.Data.broadcastCustomerChatMesg(MesgObject)}, Number(foundAction['$']['showAtSecond']));
TypeError: undefined is not an object (evaluating 'this.Data.broadcastCustomerChatMesg')
break;
case 'supportchat':
console.log('send a support chat message ');
break;
default:
console.log('defaulted');
} //end switch
});// end foreach
}
}
Все они получают неопределенную ошибку.