最近使用ionic3时,http请求之后,data返回来了,控制台可以console.log打印出来,但是挂不到页面上;
{
"city":
"00000",
"code":
"string0",
"flag":
"0000",
"info": {
"contact":
"13000000000",
"imgList": [
"0000000000"
],
"subject":
"string",
"workTime":
"9:00-21:000000"
},
"location": {
"x":
0,
"y":
0
},
"message":
"0000......",
"name":
"0000",
"provice":
"string",
"shopImg":
"assets/img/6.jpg",
"sid":
"string",
"tags": [
"000000"
],
"workStatus":
"00000",
"zone":
"string"
}
想要挂info里面的contact的电话号码,
http请求代码如下,都可以console.log,
ngOnInit():
void {
this.
shops=
this.
http.
get(
'assets/data/data.json');
this.
shops
.
map(
res
=>
res.
json())
.
subscribe(
data
=> {
console.
log(
data);
this.
results =
data;
console.
log(
this.
results.
info);
console.
log(
this.
results.
info.
contact);
})
html如下:
<
p
>{{ results.info.contact }}
</
p
>
怎么样都不显示,弄了好久;
解决方法如下:
results:
any = {
info:{} };
注意{},就是加上它就好了!