angular - 我需要从此 API 中获取“Citta”的值并将其保存到变量中,我该怎么做?
问题描述
这是 API:
0: {CodSoggetto: 22543, CognomeDenominazione: "STELLA", Nome: "ANTONIO", CF_PI: "STLNTN29S26C975F",…}
CF_PI: "STLNTN2G9S26C975F"
CNascita: "CONVERSANO"
CResidenza: "CONVERSANO"
Cap: "7054014"
Citta: "CONVERSANO"
CodSoggetto: 24543
Cognome: "STELLA"
Deceduto: "N"
Nome: "ANTONIO"
Residente: "S"
Sesso: "M"
这是我的服务:
getCitta(){
return this.http.get(`${this._host}/Contribuente`).pipe(map((res: any) => {
this._Var = res.Citta;
return this._Var;
}));
当我使用“this._Var”时,它显示未定义。
解决方案
解决方案:
getCF(): Observable<string> {
return this.http.get(`${this._host}/Contribuente`)
.pipe(
map((res: any) => {
if (typeof res === 'object') {
if (res instanceof Array) {
return res[5].Citta;
}
return res.Citta;
}
})
);
}
推荐阅读
- spring-boot - Spring rabbitmq 任务队列并发
- python - 为什么我的理解列表不起作用?
- python - 如何使用户输入更改布尔值?
- javascript - 在 React 中加载内部图像的问题
- terraform - Terraform 禁用数据准备
- node.js - 如何让后台 API 服务器在 React 项目中使用热重载?
- veins - 静脉中的紧急信息在哪里?
- python - 带有单个输入语句的快速计算器
- machine-learning - 在回归任务中,我如何找到哪些自变量将被忽略或不重要?
- selenium-webdriver - 悬停电子 - > 手机和点击在 Flipkart UI 中使用 Selenium 使用 Chrome