Angular 角度6-使用*ngFor显示数据(数据未显示)
我有一些数据如下所示: 在我的Angular 角度6-使用*ngFor显示数据(数据未显示),angular,typescript,angular6,Angular,Typescript,Angular6,我有一些数据如下所示: 在我的app.component.html上,我有以下内容: <ul> <li *ngFor="let data of myData">{{data.id}}</li> </ul> 然后: this.myData = obj; // Obj contains the data 如何解决此问题? <ul *ngFor="let data of myData"> <li>{{data.id}
app.component.html
上,我有以下内容:
<ul>
<li *ngFor="let data of myData">{{data.id}}</li>
</ul>
然后:
this.myData = obj; // Obj contains the data
如何解决此问题?
<ul *ngFor="let data of myData">
<li>{{data.id}}</li>
</ul>
{{data.id}
您正在创建多个
元素,而您可能希望有多个(列表项)
元素:
<ul>
<li *ngFor="let data of myData">{{data.id}}</li>
</ul>
- {{data.id}
因为我猜您创建了类似这样的数组对象
myData = [
{
'@attributes:': 'id:1'
},
{
'@attributes:': 'id:2'
}
];
这是错误的,必须是这样。首先检查数组或数组对象
myData = [
{
attribute: 'abc',
id: 1
},
{
attribute: 'bcs',
id: 2
}
];
和在Html文件中
<ul>
<li *ngFor="let data of myData">{{data.id}}</li>
</ul>
- {{data.id}
像这样将数据赋给myData变量==>
this.myService.myFunction().subscribe(res=>
this.myData = res['listResponse']['@attributes']['instance']
)}
你能显示console.log(myData)打印的内容吗?console.log将显示我在html页面中的问题中提供的数据。使用插值查看数据对象是什么样的
{{data.@attributes.id}看到它看起来更好
当我将app.component.ts代码更改为:this.myData=obj.listResponse.instance时,它不喜欢@attributes中的@字符;没有错误,但空的console.log(obj.listResponse.instance[0])
吗?
this.myService.myFunction().subscribe(res=>
this.myData = res['listResponse']['@attributes']['instance']
)}