Json 使用Angular2在HTML中显示对象
在我的组件中,我得到了变量名peopleDetails中的json 示例JSON:Json 使用Angular2在HTML中显示对象,json,angular,Json,Angular,在我的组件中,我得到了变量名peopleDetails中的json 示例JSON: { name:'xxxx', age:123, details:{ qualification:'abc', yearofPassing:1111 } } 我试着像这样在我的html中显示它 <div>{{peopleDetails.name | async}} {{peopleDetails.name | async} 但是我无法获得json的属
{
name:'xxxx',
age:123,
details:{
qualification:'abc',
yearofPassing:1111
}
}
我试着像这样在我的html中显示它
<div>{{peopleDetails.name | async}}
{{peopleDetails.name | async}
但是我无法获得json的属性
当我这样尝试时,它正在打印整个json
<div>{{peopleDetails.name | async | json}}
{{peopleDetails.name | async | json}
但是我想访问Json的所有属性 很难从你的问题中看出问题所在。 猜测:
{{(peopleDetails|async)?.name}
为什么要使用|async
?因为我是从存储中选择的它不是有效的JSON,它应该是{name:'xxxx',age:123,details:{qualification:'abc',yearofPassing:1111}}你能解释一下为什么我们使用问号进行访问以防止(peopleDetails | async)时出错吗
返回null
,因为null
没有名称
属性
<div>{{(peopleDetails | async)?.name}} </div>