我有来自Web API的数据绑定,并将其绑定到我的视图,但是一个字段引起了问题,因为它在名称desc_ci.serial_number
的中间有一个点,我到目前为止,我正在尝试以下代码:
API的API数据结构
desc_ci.serial_number: "cxxxxxxxx"
description: ""
etc etc
html
<span class="text-gray">{{receivedIncident.desc_ci.serial_number}}</span>
.ts文件
receivedIncident: any;
constructor(private service: nowService,
private appComponent: AppComponent,
private userService: UserService,
private router: Router,
private http: HttpClient,
private route: ActivatedRoute
) {
this.receivedIncident = { number: '', opened_at: '', description: '', short_description: '', desc_ci.serial_number: ''}; this.receivedLocation = {city:null, country: null}
}
private getIncident() {
this.service.getIncident(this.s_id, this.c_id).subscribe((data) => {
this.loading = true;
console.log('Result - ', data);
console.log('incident data is received');
this.loading = true;
this.receivedIncident = data.result[0];
})
}
我遇到错误:找不到名称'desc_ci'??
有什么想法吗?
答案 0 :(得分:1)
两个可能的问题。
那是格式错误的json。如果存在非法的属性名称字符,则应将该名称加引号。示例:"desc_ci.serial_number" : "value"
。
您的代码还需要正确引用它,您可以使用属性索引器{{receivedIncident['desc_ci.serial_number']}}
进行引用。