【发布时间】:2017-03-01 23:21:44
【问题描述】:
我通过 ajax post call 收到了来自 api 的 json 响应。这是我的 json 响应
JSON 响应:
{ “s”:是的, “米”: { “我”:10, "n": "苹果手表", “p”:“14000” }}
实际上,在我的打字稿代码中,我发出了显示 JSON 响应的警报。它运作良好。 当我尝试对 HTML 元素使用响应值时。失败了。
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.
错误
Runtime Error
Error in ./HomePage class HomePage - caused by: Cannot read property 'm' of undefined
【问题讨论】:
标签: angular ionic2 hybrid-mobile-app