【发布时间】:2022-11-16 00:01:21
【问题描述】:
我希望在 html 中显示变量 LABEL
JSON 文件是here。
我正在尝试从 JSON 检索数据,但出现错误消息:
required in type 'Tit'.ts(2741) instrument-info.response.ts(8, 5):
'ADVTITRE' is declared here.
我真的不明白这个问题...
这是我目前的步骤。
仪器信息.response.ts
export interface Tit {
ADVTITRE: {
BASIQUETITRE: {
SVM: number;
ISIN: string;
STOCK: string;
LABEL: string;
PLACE: number;
PLACELABEL: string;
REGR: number;
REGRLABEL: string;
DEVISE: string;
COURS: {
DATE: string;
TIME: string;
VALUE: number;
HIGH: number;
LOW: number;
CLOTURE: number;
};
};
EXIST: number;
...
};
}
细节.component.ts
details ? : Tit;
svm: string | null = null;
ngOnInit(): void {
this.svm = this.activatedRoute.snapshot.paramMap.get('svm');
if (!this.svm) {
this.goBack();
return;
}
this.getDetails();
}
private getDetails(): void {
this.service.getInstrumentInfo(this.svm!).pipe(
takeUntil(this.unsubscribe$)
).subscribe(res => {
if (res.RETURNCODE === ApiResponseCodeEnum.Ok) {
console.log(JSON.stringify(res.TIT.ADVTITRE.BASIQUETITRE));
this.details = res.TIT.ADVTITRE.BASIQUETITRE; <--- my error
}
});
}
但是,我在控制台中检索数据
非常感谢您的帮助。
【问题讨论】:
-
this.details = res.TIT;而不是this.details = res.TIT.ADVTITRE.BASIQUETITRE; -
@Mike S. 非常感谢。
标签: angular