【发布时间】:2016-12-15 16:17:10
【问题描述】:
有人可以帮助我理解这一点。我学习 Angular 2 的教程演示了使用接口通过 Observable 存储日期。即:.map((response: Response) => response.json())。
我发现的一个问题是我的接口属性定义必须与 json 属性完全匹配。 IE;如果 json 属性是 _custNum,我的接口必须使用完全相同的名称 _custNum。如果我将名称更改为“custNum”,它将不会映射。这只是接口的规则吗?
示例代码:
export interface ICustSearch {
_custNum: string;
_custName: string;
_address: string;
_city: string;
_state: string;
_zip: string;
_county: string;
_phone: string;
}
return this._http.get(APIRoutes.custSearchLocal, {headers: headers})
.map((response: Response) => <ICustSearch[]>
response.json())
.catch(this.handleError);
现在,如果我将上述界面中的属性“_custNum”更改为“custNum”,则地图将在客户编号上失败。有没有办法解决这个问题。还有,为什么要使用接口而不是类来映射json对象,有什么好处呢?
提前致谢。
【问题讨论】:
标签: angular interface observable