我无法列出 json 文件。
我的代码:
this.http
.post(link, data, options)
.map(res => res.json().d)
.subscribe(
data => {
this.profile = JSON.parse(data);
console.log(this.profile);
},
err => {
console.log("ERROR!: ", err);
}
);
Console.log 打印:
对象 {用户:对象,类:数组(1)}
{
"user":{
"name":"Name",
"date":"19880210",
"email":"[email protected]",
"about":"About me",
"picuteUrl":"http://www.url.com/Midia/User/picture.jpeg",
},
"class":[
{
"id":"82",
"name":"Class 01"
}
]
}
我还可以在 TypeScript 文件中获取这些值
console.log(this.profile.user.name);
console.log(this.profile.class[0]);
console.log(this.profile.class[0].name);
但是在 html 代码中我没有得到这个值。
<input type="text" value="{{profile.user.name}}">
错误:
ion-dev.js?v=1.1.4:156 TypeError: Cannot read property 'usuario' of undefined
提供的代码中没有您访问的地方,usuario。您可以使用elvis/safe
运算符来检查值是否存在
<input type="text" value="{{profile?.user?.name}}">
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句