I am working on a straightforward typescript function to retrieve a list along with its status, and my model is defined as follows:
export interface CashPaymentModel {
success: boolean;
data: CashSpendAdHocDTO[];
}
export interface CashSpendAdHocDTO {
dueDate: string;
gross: string;
moveStageName: string;
paidDate: string;
service: string;
status: string;
timestamp: string;
type: string;
}
This is how my service method looks like:
getCashPayments(policyVersionId: number, employeeId: number): Observable<CashPaymentModel> {
return this.http.get<CashPaymentModel>(`/api/v1/policy/configuration/versions/${policyVersionId}/details?employeeId=${employeeId}`);
}
Now, I need to display the list from the response (the second attribute in the response) in a table within the template. How do I assign this table's data source?
tableDataSource: Observable<CashPaymentModel>;
testMethod() {
this.tableDataSource = this.cashPaymentService.getCashPayments(this.policyVersionId, this.employeeId).subscribe((data: CashPaymentModel) => {
this.tableDataSource = data; .......BLA BLA BLA
});
}
Could you help me understand how to correctly assign tableDataSource from the second attribute of the response in TypeScript?