Im trying to get data from a .json file that is recieved via post method to a external server, using ajax function and display it all on html (tags and data). I can get the json data and display it via console log, however im not able to iterate over it, or simply display in on the html side.
I've tryed to create a public array and push the response to it, create a function, etc.. but looks like ajax function loads after it, and there's no data at all, then i've tried to concat a string with the values that i get on console, but no success.
I can't even get the actual data, only the tags. Im a little bit confused here. Can some one help me?
Here's my code and what it displays on console.
component.hmt:
<ul>
<li>{{res}}</li>
</ul>
component.ts
public res = "";
ngOnInit() {
let settings = {
"async": true,
"crossDomain": true,
"url": "ip/to/api",
"context": this, //added this
"method": "POST",
"data": "\"dataApi\"",
};
$.ajax(settings).done(function (response) {
console.log(response);
this.res = response; //added this
for(let i in response)
{
//console.log(i);
this.res += i + " - ";
for(let j in response[i])
{
//console.log(j);
this.res += j + " : \n ";
for(let t in response[i][j])
{
//console.log(t);
this.res += t +"\n";
}
}
}
console.log(this.res);
return this.res;
});
}
}
Here's the output on console.log: the thing is that on console log i can get all the tags : data, but i can't never get the data on res string to display.
Console.log(response) : All the data i need to display.
this.res : the tags without any data.
Thanks in advance!!
Edit: Here's the output of {{res | json}} on html side:
{ "Challenges": [ { "Challenge.Closed": false, "Challenge.EndSubmissionDate": "Sat Feb 13 00:00:00 GMT 2010", "Challenge.Title": "net.Partner", "Challenge.CompositeId": "Id=3_Tenant=103", "Challenge.Code": "2010/001"....
I have the json like text based..i want for example:
Challenge.Closed : false
....
Idea.id: 4
...
and access some of the tags that i know that exists, like id.. Do i have to map it?