我想从我的JSON API获取特定数据,但我总是在我的控制台中获得undefine
。从JSON API获取特定数据
这里是我使用http get
让我的JSON API我的TS文件:
我的TS码:
this.http.get('http://xxxxx.com/xxx/api.php/customer?filter=customer.customer_id,eq,21&transform=1')
.map(res => res.json())
.subscribe(data => {
this.customer = data.customer;
console.log(this.customer);
this.cus_city = this.customer.customer_delivery_city_address;
console.log("City Address: " +this.cus_city)
}, (err) => {
console.log("Something went wrong.");
});
这里是我的控制台API结果:
我想要得到的是customer_delivery_city_address
。我试图通过this.customer.customer_delivery_city_address
到this.cus_city
变量,并将其显示到我的控制台console.log("City Address: " +this.cus_city)
,但我得到undefined
结果。一切都很好,当我把它叫做我的HTML {{customer.customer_delivery_city_address}}
。我仍然不知道如何将特定数据传输到我的TS文件。希望任何人都可以帮助我。先谢谢你。
angular1 or angular2? –
尝试this.customer [0] .customer_delivery_city_address – JayDeeEss
我正在使用angular2。 – Patrick