【发布时间】:2019-08-16 10:12:18
【问题描述】:
我从离子模板中的调用中得到一个未定义的错误:
ERROR TypeError: "this.x is undefined"
但是当我将 this.x 记录到控制台时,它看起来很好。
也许这是一个简单的问题,但我刚开始学习这个。 如果有人可以提供帮助,将不胜感激:)
this.http.get('xy.json', {responseType: 'text'})
.subscribe(response => {
this.x = JSON.parse(response);
console.log(this.x);
});
getCurrentObj() {
return this.x[0];
}
模板:
{{ getCurrentObj().text }}
json:
{
"0": {
"text" : "This is sample text 1",
"type" : "xy"
}
}
来自 console.log 的 this.x:
Object(1)
0: Object { text: "This is sample text 1", type: "xy", … }
<prototype>: Object { … }
【问题讨论】:
标签: javascript angular typescript ionic-framework httpclient