Angular Web api未正确绑定到中的html格式
我有来自web api的以下格式的数据:Angular Web api未正确绑定到中的html格式,angular,Angular,我有来自web api的以下格式的数据: { "result": [ { "location.city": "xxxx", "location.country": "xxxx", "location.street": "xxxxxx", }, ] } 当我试图将其与我的观点联系起来时,我正在做以下事情: ts文件 html: [(ngModel)]="selectedStr
{
"result": [
{
"location.city": "xxxx",
"location.country": "xxxx",
"location.street": "xxxxxx",
},
]
}
当我试图将其与我的观点联系起来时,我正在做以下事情:
ts文件
html:
[(ngModel)]="selectedStreet"
但什么都没出现?有什么想法吗?我想这只是这里的打字脚本代码的问题,selectedObj.location.street不是你想要的,它应该是selectedObj['location.street'] 详细说明一下,像这样的对象是完全有效的:
{
"location": {
"street": "xxxxx"
},
"location.street": "yyyyy"
}
因此,您可以访问不同的属性,如下所示:
obj.location.street // xxxxx
obj['location'].street // xxxxx
obj['location']['street'] // xxxxx
obj['location.street'] // yyyyy
obj.location.street // xxxxx
obj['location'].street // xxxxx
obj['location']['street'] // xxxxx
obj['location.street'] // yyyyy