자바 스크립트 날짜로 변환해야하는 ISO 날짜를 반환하는 API가 있습니다. 자동으로 매핑을 수행하는 HTTPClient 모듈을 사용하고 있지만 수신 된 데이터를 변환하지 않는 것 같습니다.각도 4 HttpClient 데이터 매핑
HTTP 모듈을 사용하면 작동하지만 HTTPClient를 사용하고 싶습니다.
내 코드는 아래에 있습니다.
export class Product{
datetime: string;
qty: number;
constructor(date: string, hr: number) {
this.datetime = new Date(Date.parse(date));
this.heartrate = hr;
}
}
@Injectable()
export class BandHeartRate {
private Url = 'http://192.168.1.1:6000';
constructor(private http: HttpClient) {}
public getProduct(): Observable<Product[]> {
return this.http.get<Product[]>(`${this.Url}/web/api/v2/product`,
{headers: this.getHeader()});
}
private getHeader() {
const header = new HttpHeaders();
header.append('Accept' , 'application/json');
return header;
}
}
}
어디서'getProduct()'를 구독하나요? 'Product' 클래스는 어디에서 호출하고 있습니까? – LLai