我正在使用一个Observable,并且在将其正确映射到模型类时遇到了问题。根据这里的建议,我修复了套管问题,但是将模型更改为Camel套管并不能完全解决问题。数据是否绑定到httpresponse而不是我的对象?
我的模型班:
export class Lease implements ILease {
public id: string;
public emailAddress: string;
public make: string;
public carModel: string;
public year: number;
...
}
我的component.ts:
this.sub = this.leaseSvc.GetLease(this.id).subscribe(
(data: Lease) => {
console.log(this.lease);
console.log(this.lease.make); // undefined
console.log(this.lease.Value.make); // works but is wrong
}...
我的控制台输出:
{ContentType:null,SerializerSettings:null,StatusCode:null,值:{…}} ContentType:nullSerializerSettings:nullStatusCode:nullValue:carModel:“ Sorento” currentMileage:355emailAddress:“ aaa@aaa.com” firstName:“ Bill “ id:” 5be8925ea21e8b3ef0ac08e9“姓氏:” Smith“租赁长度:60leaseStartDate:” 2018-11-01T04:00:00Z“ leaseStartMileage:10make:”起亚“ mileSets:[] mileageOverageCharge:0.2password:”“ passwordHash:” $ 2b $ 10 $ QZbcf / sWOmBVjDlZ.LvIwOuGb6pq2EaIzZbuM4EhGyUYlFAC.7YlK“ trackingInfo:{leaseEndDate:” 2023-11-01T04:00:00Z“,totalMileageAlloted:50000,MilesUsed:345,AllowedMileed:605,AllowedMileed :10000zipCode:“ 30303” proto :对象__proto__:对象
lease-stats.component.ts:41未定义
lease-stats.component.ts:42起亚
我的service.ts代码:
GetLease(id: string): Observable<Lease> {
return this.http.get<Lease>(this.serviceUrl + id, this.secureHttpOptions);
}
答案 0 :(得分:0)
问题出在Angular应用程序调用的.Net Core RESTful服务中。它返回的JsonResult在“值”元素下具有预期的对象。 Angular中该类的原始Pascal大小写可能最初也是一个问题。