我理解这是一个基本问题,我也确实访问了以下链接,但我也可以使用更多帮助。
Angular2 typescript map response to new type Map response to model object How to map model class with api response Angular 5
我在WCF中有Rest api,它会产生以下响应:
"GetDeliveryManagerProfileResult": {
"Address": "testasasa",
"DateOfBirth": "Tue, 13 Aug 2019",
"EmailAddress": "ameerali.web@gmail.com",
"FullName": "Ameer Ali",
"HealthInsurance": null,
"MemberSince": "August 2019",
"MobileNumber": null,
"Nationality": "Pakistani",
"RoleName": "Delivery Admin",
"ServiceContract": null
}
我在Angular 8中对结果进行了加法处理。我具有以下模型来映射属性
export class Profile {
FullName: string;
RoleName: string;
MobileNumber: string;
EmailAddress: string;
Address: string;
DateOfBirth: string;
MemberSince: string;
Nationality: string
}
以下Angular服务正在对数据进行填充。.但是无法在属性中进行映射,
getUserProfile(): Observable<Profile> {
const url = this.url +'/GetDeliveryManagerProfile';
return this.http.get<Profile>(url).pipe(
catchError(this.handleError)
);
}
即使这是在component.ts中也不起作用。
export class DeliveryAdminProfileComponent implements OnInit {
constructor(private accountService: AccountService) { }
profile: Profile;
ngOnInit() {
this.getUserProfile();
}
getUserProfile() {
this.accountService.getUserProfile()
.subscribe(data => {
console.log((data));
this.profile = data;
});
}
}