json 응답을 개체에 전송하려고 할 때 문제가 있습니다. 개체의 모든 속성이 정상입니까? 여기 각도 : 개체 모델로 JSON 응답이 작동하지 않습니다.
public getSingle = (keys: any[]): Observable<Badge> => {
return this._http.get(this.actionUrl + this.getKeysUrl(keys))
.map((response: Response) => response.json() as Badge)
.catch(this.handleError);
}
내 배지 모델 : 여기
내 아약스 요청 여기
export interface Badge {
badgeNumber: number;
authorizationLevel: number;
endOfValidity: Date;
}
하고 나는 서비스 함수를 호출하고 난 문제에 직면하고있어 여기서
을this._badgeService.getSingle(this.ids).subscribe(
(badge: Badge) => {
console.log(typeof(badge.endOfValidity)); // <-- returning string and not Date
},
error => console.log(error);
});
'Badge'는 * 어설 션 *이므로 실제로 아무 것도 던지지 않습니다. JSON 데이터에서 직접 새 배지 객체를 만들어야합니다. – jonrsharpe
내 생각에 그걸하는 가장 좋은 방법 위에 내게 말해 주겠니? –