0
각도 2를 사용하고 있으며 객체 컬렉션을 반환하기 위해 끝점을 호출하려고합니다.Observable Map이 typescript 클래스로 캐스팅되지 않습니다.
나는 다음과 같은 JSON
[{"id":610,"branch":"Coventry"},{"id":620,"branch":"Shoreham"}]
나는 다음과 같은 코드
를 사용하여 엔드 포인트를 호출하는 노선 서비스가 반환하는 API 엔드 포인트를export class Route
{
public branchId: number;
public branch: string;
public isTest: boolean = true;
}
다음 TypesScript 클래스를 가지고
public getRoutes(): Observable<Route[]>
{
const url = 'http://localhost/routes';
return this.http.get(url)
.map((response: Response) =>
{
const routes: Route[] = response.json() as Route[];
if (routes.length > 0) {
console.log(routes[0].isTest);
//This returns undefined I was expecting the boolean value true
}
return routes;
}
)
.catch(e => this.httpErrorService.handleError(e));
}
response.json()이 데이터 유형 R로 형변환되지 않는 것처럼 보입니다. 외출. 왜 이런거야?
트릭을 한 Teddy에게 감사드립니다. –