【发布时间】:2018-08-30 09:03:30
【问题描述】:
我目前有一项服务,它从显示潜在客户列表的 json 文件中获取 json 对象数组。每个潜在客户都有一个 id,当单击此列表中的潜在客户时,它会将用户带到在 url 中具有此 id 的视图,即 (/lead/156af71250a941ccbdd65f73e5af2e67)
我一直试图通过我的潜在客户服务通过 id 获取此对象,但无法使其正常工作。我哪里错了?
另外,我在我的 html 中使用了两种方式绑定。
服务
leads;
constructor(private http: HttpClient) { }
getAllLeads() {
return this.http.get('../../assets/leads.json').map((response) => response);
}
getLead(id: any) {
const leads = this.getAllLeads();
const lead = this.leads.find(order => order.id === id);
return lead;
}
组件
lead = {};
constructor(
private leadService: LeadService,
private route: ActivatedRoute) {
const id = this.route.snapshot.paramMap.get('id');
if (id) { this.leadService.getLead(id).take(1).subscribe(lead => this.lead = lead); }
}
JSON
[
{
"LeadId": "156af71250a941ccbdd65f73e5af2e66",
"LeadTime": "2016-03-04T10:53:05+00:00",
"SourceUserName": "Fred Dibnah",
"LeadNumber": "1603041053",
},
{
"LeadId": "156af71250a999ccbdd65f73e5af2e67",
"LeadTime": "2016-03-04T10:53:05+00:00",
"SourceUserName": "Harry Dibnah",
"LeadNumber": "1603021053",
},
{
"LeadId": "156af71250a999ccbdd65f73e5af2e68",
"LeadTime": "2016-03-04T10:53:05+00:00",
"SourceUserName": "John Doe",
"LeadNumber": "1603021053",
}
]
【问题讨论】:
标签: json angular typescript object