I have an api which will return the map response like .
{thomas: 3, test70: 2, tim: 2, elin: 2, sumeet12: 1}
I want to iterate in angular but unfortunately i got error while trying this.
Error Got ::
This expression is not callable. Type 'Number' has no call signatures.ts(2349)
this.testObject.forEach((value: number, key: string) => {
console.log(key, value);
});
But i am able to iterate in the html using below code..
In html
<div *ngFor="let item of testObject | keyvalue: originalOrder; let i=index">
<span *ngIf="i<3">
Key: <b>{{item.key}}</b> and Value: <b>{{item.value}}</b>
</span>
</div>
In .ts file
testObject: { [key: string]: number };
showresult: any;
getQuizResult(id){
this.service.getResult(id).subscribe((stndrdResp: Response) => {
this.showresult = stndrdResp.obj; // this will return a object
this.testObject = this.showresult; // assigning the key value response to testObject
});
}
Basically i want to iterate the backend api response inside the getQuizResult so that i can perform some action. Appreciate your valuable suggestion.