i want to bind my api response to my model.ts file but it giving me error
// following is my model.ts
export class Data{
status:boolean;
data:statistics[];
}
export class statistics {
State: string;
SurveyorName: string;
NoOfInt: number;
SampleReceived: number;
CancelledEntries: number;
Approved: number;
DisApproved: number;
}
export class Job{
name:string;
position:string;
salary:number;
}
// following is my api response
objectOfArraySample =
{
"status": true,
"data": {
"statistics": [
{
"State": "Karnataka",
"SurveyorName": "Keval Kakdiya",
"NoOfInt": "2",
"SampleReceived": "2",
"CancelledEntries": "0",
"Approved": "1",
"DisApproved": "1"
},
{
"State": "MAHARASHTRA",
"SurveyorName": "Keval Kakdiya",
"NoOfInt": "0",
"SampleReceived": "0",
"CancelledEntries": "1",
"Approved": "0",
"DisApproved": "0"
}
],
}
}
// following is my .ts file
import { Data } from './data.model';
import { Job } from './data.model';
result: Data;
result1: Job[];
ngOnInit() {
this.result1 = this.arrayOfObjectSample;
this.result = this.objectOfArraySample; // here i am assingning value but it give me error
/*this.result.statistics.push({
})*/
}
//following error is throwing
Type '{ "status": boolean; "data": { "statistics": { "State": string; "SurveyorName": string; "NoOfInt": string; "SampleReceived": string; "CancelledEntries": string; "Approved": string; "DisApproved": string; }[]; }; }' is not assignable to type 'Data'.
Types of property 'data' are incompatible.
Type '{ "statistics": { "State": string; "SurveyorName": string; "NoOfInt": string; "SampleReceived": string; "CancelledEntries": string; "Approved": string; "DisApproved": string; }[]; }' is missing the following properties from type 'statistics[]': length, pop, push, concat, and 26 more.