嗨,我正在学习 Angular 8,作为一名学习者,我有很多疑问。我正在详细分享我的一个疑问。我希望你们中的一些人可以轻松地帮助和纠正我。
我有一项服务使用 Web API 并返回一些公司详细信息,例如
0: {CompanyId: 1, Name: "xxxx", Address: "bn"}
1: {CompanyId: 2, Name: "yyyy", Address: "tv"}
服务.ts
GetAll(): Observable<IEmployee>{
return this.httpClient.get<IEmployee>(this.apiUrl + "GetCompany_test").}
组件.ts
private emp : IEmployee;
getAllEmployees(){
this.service.GetAll().subscribe(
response => {this.emp =response;console.log(response)},
error => console.log(error)
);}
IEmployee.ts
export interface IEmployee{
fullName:string,
Email:string,
Mobile:string,
City:string,
HireDate:Date
}
即使我使用 Observable 的Observable<IEmployee>
. 那么这里有什么需要铸造的呢?当我投射到 Employee 并且我很容易获得非 Employee 数据时,它应该让我在控制台中出现一些警告或错误,对吗?我对正在发生的事情完全感到困惑。
有人可以帮我理解铸造的概念,并建议我正确使用铸造。
问候。