So I'm trying to map and object. It has a key and that key has a value. I get the whole receipt from the server and this is the part with payments (It's the preview of the response I got):
paragonSequenceNumber: null
payments: {CARD: 4, CASH: 8}
pkp: "BBBBBBBBBBBBBBBBBBBBB"
So I'm mapping it and then using it in html with *ngFor and then writing out the values for the keys. this is my ReceiptDTO:
export interface ReceiptDTO {
payments: {[key: string]: number }; // key: ReceiptPaymentType (enums)
}
This is my ReceiptViewModel
interface ReceiptViewModel {
payments: {[key: string]: number }[]; // I'm not actually sure what to put here
}
This is the PaymentViewModel
interface PaymentViewModel {
CASH: number;
CARD: number;
VOUCHER: number;
}
And this is what I tried using for the ReceiptViewModel ,first Just using it like this:
payments: data.receipt.payments,
Then like this:
payments: Object.entries(data.receipt.payments).map(([key, value]) => {
return <PaymentViewModel>{
CASH: value.CASH,
CARD: value.CARD,
VOUCHER: value.VOUCHER,
};
})
But none of the work and what I'd like to happen is to be able to use it in html like this:
<tbody *ngFor="let payment of receipt.payments">
<tr>
<th>{{'models.Receipt.payments.paymentType.CASH' | translate}}</th>
<th>{{payment.CASH}}</th>
</tr>
<tr>
<th>{{'models.Receipt.payments.paymentType.CARD' | translate}}</th>
<th>{{payment.CARD}}</th>
</tr>
</tbody>