I have this json data that is being returned from the server that won't map to my typescript object. I am sure it's a small issue but I can't find it, nor can my teammate.
JSON: {"labels: ["foo","bar"], "sums":null, "sid":0, "cid":0}
My typescript object:
import {Claim} from './Claim';
import {ResponseInfo} from './ResponseInfo';
import {Rule} from './Rule';
import {ServiceLine} from './ServiceLine';
export interface ClaimResponse {
labels: string[];
}
This is my service:
import {Injectable} from '@angular/core';
import {Observable} from 'rxjs/Observable';
import {RequestOptions, Http, Response, Headers, URLSearchParams} from '@angular/http';
import {ClaimResponse} from './ClaimResponse';
@Injectable()
export class EvaluationDetailService {
constructor(private http: Http) { }
getEvaluationDetail(): Observable<ClaimResponse> {
return this.http.get('./EvaluationDetail/GetEvaluationDetail')
.map((res: Response) => <ClaimResponse>res.json())
.do(data => console.log(JSON.stringify(data)))
.catch(this.handleError);
}
private handleError(error: Response) {
console.error(error);
return Observable.throw(error.json().error || 'Server error');
}
}
Here is my component:
@Component({
selector: 'claim-evaluationdetail',
templateUrl: './Scripts/EvaluationDetail/evaluationdetail.component.html',
providers: [EvaluationDetailService, HTTP_PROVIDERS],
directives: [ResponseInfoComponent, ServiceLineComponent, OverlayPanel]
})
export class EvaluationDetailComponent implements OnInit {
constructor(private _evaluationDetailService: EvaluationDetailService) { }
claimResponse: ClaimResponse ;
visible: boolean = false;
showRules: boolean = false;
ngOnInit() {
this.getClaimResponse();
}
getClaimResponse() {
this._evaluationDetailService.getEvaluationDetail().subscribe(claimResponse => this.claimResponse = claimResponse);
}
}
The data gets returned perfectly fine from the server (see the JSON data above), but if I try to access anything involving "this.claimResponse", it is undefined.
What am I doing wrong?