【发布时间】:2020-10-22 16:56:20
【问题描述】:
我有一个工作 api,它在查询时返回一组表实体对象。这是我的 Angular 应用程序中对应的 tableEntity
export interface TableEntity {
partitionKey: string;
rowKey: string;
ownerid: string;
filetype: string;
companyName: string;
parentID: string;
isdirectory: boolean;
filesize: Int32Array;
}
在我的 Angular 应用程序中,我使用服务查询此 api,这是联系 api 并将表实体对象发送到组件的相关代码
getFileStructureData(){
return this.http.get(this.baseUrl + 'list').pipe(
map((user: TableEntity) => {
return user;
})
)
现在在组件内部我可以访问这个对象,当我控制台记录这个对象时,它会按预期返回对象数组。
this.TableService.getFileStructureData().subscribe(response => {
console.log(response);
}, error => {
console.log(error);
})
但是当我尝试通过控制台记录对象的各个属性时,
this.TableService.getFileStructureData().subscribe(response => {
console.log(response.companyName);
}, error => {
console.log(error);
})
我在控制台日志中得到未定义的值。如何访问订阅函数中 tableEntity 对象的各个属性?非常感谢您的帮助
【问题讨论】:
-
你确定你没有得到实体数组吗?
-
“它按预期返回对象数组”。
map((user: TableEntity) => {会不正确,它需要是map((users: TableEntity[]) => {或类似的权利?就像在一组用户中一样。此外,该地图也没有做任何事情,您可以简单地return this.http.get< TableEntity[]>(this.baseUrl + 'list')。 -
数组没有
.companyName属性。如果你想打印出它的一个属性,你可以试试response.length。如果您想要响应数组中第一个TableEntity的companyName,您可以尝试console.log(response[0].companyName)
标签: angular rxjs pipe observable subscribe