I have received a json response from an api through ajax post call.Here is my json response
JSON Response:
{ "s": true, "m": { "i": 10, "n": "Apple Watch", "p": "14000" }}
Actually in my typescript code, I made an alert to display JSON response. It works well. When I tried to use the response values to the HTML elements. It was unsuccessful.
TypeScript:
let headers = new Headers({ 'Content-Type': 'application/json'});
this.value = { 'uid': 10 };
let body = JSON.stringify(this.value);
this.http.post(url, body, headers)
.map(res => res.json())
.subscribe(
data => {
alert(JSON.stringify(data));//Alert displays the response successfully
this.insdata=data;
},
err => {
console.log("Oops!");
}
);
HTML
<h2>{{insdata.m.n}}</h2> //I cannot get the value here.
Error
Runtime Error
Error in ./HomePage class HomePage - caused by: Cannot read property 'm' of undefined