My webapp retrieves data via Json and places it in objects for display. I have successfully implemented this process twice using services and classes. However, when I recently copied and pasted the old code with some modifications to redirect to the correct classes, I noticed that I am now receiving an array of functions instead of an array of objects.
https://i.sstatic.net/lwpdm.png
https://i.sstatic.net/7hCmi.png
Below is my constructor that utilizes the service classes and outputs to the console:
constructor(private featureService : FeatureService, private scenarioservice : ScenarioService, private failuresService : FailuresService){
// Retrieving features and failures
this.featureService.getFeatures().subscribe(res => {
this.featureArray = res.getFeatureArray();
console.log(res.getFeatureArray());
});
this.failuresService.getFailures().subscribe(res => {
this.failureArray = res.getFailureArray();
console.log(res.failures[0].method);
console.log(this.failureArray);
});
}
}
Here is the implementation of failuresService.getFailures:
import { Injectable } from "@angular/core";
import {Http, Response} from "@angular/http";
import {Failure} from "./Failure";
import {Failures} from "./failures";
@Injectable()
export class FailuresService {
constructor(protected http: Http) {}
getFailures() {
return this.http.get('http://localhost:8080/testresultaten')
.map((response: Response) => response.json())
.map(({failures = [Failure]}) => new Failures(failures));// Ignore this error message
}
}
Below is the Json structure that I receive and aim to parse into a class:
{
"failures:": [
{
"method": "canRollOneGame",
"object": "BowlingGame.GameTest"
},
{
"method": "canCountNighteeneight",
"object": "FizzBuzz.FizzBuzzTest"
}
]
}
And here are the Failure and Failures classes:
import {Failure} from "./Failure";
export class Failures {
constructor(public failures : Failure[]){}
public getFailureArray(): Failure[]{
return this.failures;
}
}
export class Failure{
constructor(public method : String , public object : String ){ }
}