I am trying to figure out how to correctly return a list of custom objects and print its contents using an HTML file.
Here's what the HTTP GET method looks like (for simplicity, I have separated some things to illustrate the problem):
[HttpGet("/atr/testing")] public List<CustomObject> GetCustomObjects() {
My TypeScript file (called home.ts) is signed and calls the HttpGet method - this is what the Home class looks like (I excluded all import sections and @Component):
export class Home { public selectedConfiguration: string = 'TESTVALUE'; constructor(private http: Http) { this.getConfigurations() .subscribe(res => { this.selectedConfiguration = res; }); } getConfigurations() { console.log('Home:getConfigurations entered...'); return this.http.get('atr/testing') .map((response) => { console.log(response); return response.json(); }); }
}
As you can see, the constructor calls getConfigurations, which calls the HttpGet method. The part that bothers me is how can I use the returned answer correctly? To form my answers in the response are returned as JSON strings (therefore, my selected configuration variable in the Home class is a string value, not a List). When I try to print the string 'selectedConfiguration' with {{selectedConfiguration}} in my HTML file, I get the following:
[object Object],[object Object],[object Object],[object Object]
If I use {{selectedConfiguration [0]}} in my HTML, I get only one: [object Object]
The list returned by the GET method should have 4 CustomObjects in it, and it looks like the JSON response has at least. Each CustomObject has variables such as "Name", "Date", "Time", etc. I tried to print the data in my HTML using {{selectedConfiguration [0] .Name}} and it does not print anything. I'm not quite sure what to do next (or if I am doing something wrong) to display information about each object.