Angular Component fails to Parse API Results
Posted: Wed Sep 30, 2020 3:16 pm
As a first step to implementing the new Angular component in our application I set up a simple test API to get an idea of how everything would hang together. I used the example code from the Get Started page as a base.
When the component received the output from the API it failed to parse as it was expecting a completely different structure. I was able to get it to work but had to actually rewrite the parsing code:
Original Code:
Modified Code:
It looks like the expected format was a Data object base64 string for the 'styles' property. Instead I got an object where the entire Data object was a base64 string within a 'Data' property which then had a base64 string for the 'styles' property. Is there a different API source which should be used or is there an issue with the component itself?
When the component received the output from the API it failed to parse as it was expecting a completely different structure. I was able to get it to work but had to actually rewrite the parsing code:
Original Code:
Code: Select all
ControllerService.prototype.loadViewer = function () {
var _this = this;
var url = this.model.requestUrl.replace('{action}', this.model.action);
this.httpClient.post(url, this.model.createPostParameters({ action: 'AngularViewerData' }, true, false), 'json').subscribe(function (data) {
_this.model.clear();
_this.stylesService.setupStyle(atob(data['styles']), 'viewer');
_this.model.options = data;
_this.checkTrExp();
_this.initAutoUpdateCache();
_this.subject.next({ action: 'viewer_loaded' });
_this.getReport();
});
};
Code: Select all
ControllerService.prototype.loadViewer = function () {
var _this = this;
var url = this.model.requestUrl.replace('{action}', this.model.action);
this.httpClient.post(url, this.model.createPostParameters({ action: 'AngularViewerData' }, true, false), 'json').subscribe(function (data) {
_this.model.clear();
var dataObject = JSON.parse(atob(data['Data']));
var styles = dataObject['styles'];
_this.stylesService.setupStyle(atob(styles), 'viewer');
_this.model.options = dataObject;
_this.checkTrExp();
_this.initAutoUpdateCache();
_this.subject.next({ action: 'viewer_loaded' });
_this.getReport();
});
};