I am just getting started with Angular 4, and have a project I've been working on that involves displaying data that is retrieved using a REST API. The data seems to be getting retrieved properly and the form getting populated correctly.
Now, one of the values returned from the API only contains a single character. I was hoping to override the setter method to expand that single character to a full string. I understand I could just change the call to return the full string, however the API is supporting by multiple front-ends and I was hoping to keep them consistent. This plunker should what I am hoping to do (without the REST API involved): Plunker example
When logging in the subscribe function of my project, fullStatus is not included:
this.service.get(id).subscribe(p => {
this.test = p;
console.log(this.test);
});
When adding the switch statement here, things work as intended, however I was hoping to have this logic be bundled into the Test class instead of the subscribe function.
this.service.get(id).subscribe(p => {
this.test = p;
switch (this.test.status) {
case 'A':
this.test.fullStatus = 'Active';
break;
case 'I':
this.test.fullStatus = 'Inactive';
break;
case 'N':
this.test.fullStatus = 'No Certificate';
break;
default:
this.test.fullStatus = '';
break;
}
console.log(this.test);
});
Is there a better way for me to handle this? Thanks in advance.