I was parsing some data via API my code for the parsing is given below,
parseXML(data) {
return new Promise((resolve) => {
var k: string | number,
arr = [],
parser = new xml2js.Parser({
trim: true,
explicitArray: true,
});
parser.parseString(data, function (err, result) {
var obj = result.ApiResponse;
for (k in obj.CommandResponse) {
var item = obj.CommandResponse[k];
arr.push({
info: item.DomainCheckResult[0],
});
}
resolve(arr);
});
});
}
This is my parser code but still i'm getting console error with
core.js:4197 ERROR Error: Uncaught (in promise): TypeError: Cannot read property 'Parser' of undefined TypeError: Cannot read property 'Parser' of undefined
So my question was what's wrong with the code? as I was returning a promise what extra could I do? I'm returning a new promise and after that I have called the parser, so how could I get error? Can anyone help me?
Well, there should be a ',' instead of the ';'. After tweaking for a long time I was finally able to solve the problem.
BTW thank you everyone who tried to help. Ohh and another thing on the top I also did an error on importing the xml2js I also had to change that.