I'm POSTing data using Angular 2 to an URL which returns back XML response, I want to convert the data to JSON so I'm using xml2js.
The conversion happens fine, but I get 'data' as undefined in 'subscribe' block. Please correct me if I'm wring, I'm guessing since xml2js is an async operation, 'data' is undefined. So how do I handle this promise of promise situation and return the transformed JSON data correctly? Code below:
this.http.post(this._yourUrl, formdata.toString(), options)
.map(res => {
xml2js.parseString( res.text(), function (err, result) {
console.dir(result); // Prints JSON object!
return result;
});
})
.subscribe(data => {
console.log(data);
});
Any help is much appreciated. Thanks!