i created a service by driving my service from
EntityCollectionServiceBase<Transaction>
My entity is called Transaction.
i am overriding the getAll method like this
getAll(): Observable<Transaction[]> {
return this.http
.get<ApiResponse>('https://localhost:xxxx/transaction/GetLastSixMonth')
.pipe(
tap((data) => {
this.notifyService.showSuccess(data.message, 'Sucess');
}),
map((res) => res.result),
catchError((err) => {
this.notifyService.showError(
'Error While Six Month Transactions',
'Error'
);
return of();
})
);
}
i am calling this getAll somewhere appropriate.
so in the component where i want to use it i am using the "entities$" property of this service like this
this.last6MonthWithdrawCount$ = this.transactionsDataService.entities$.pipe(
map((transactions) => {
const res = transactions.filter(
(transaction) =>
transaction.transactionType === TransactionType.Withdraw
).length;
return res;
})
);
so this variable "this.last6MonthWithdrawCount$ " works fine when i use it in html using asyn operator.
{{ last6MonthWithdrawCount$ | async }}
but when i want to read its value in the code by subscribing to it
this.last6MonthWithdrawCount$.subscribe(x => this.withdrawCount = x);
i dont get proper value. i get 0 . looks like it is giving me first value in the stream.
how to get the last value ? UPDATE or simply how can i get the value from this.last6MonthWithdrawCount$ in the code. actually this value is supposed to be passed to a graph data. i have graph that shows the value and also i have to pass the same value in data array of a graph.
this value 45 (same sort of stuff for the value 10) is coming from entities$.pipe code mentioned above and in the html i am doing a simple | async as mentioned above, and it works.
i have to pass the same 2 values in data of my chartJS chart.
this.myChartData.data.datasets[0].data = [this.depositCount, this.withdrawCount];
how to get this value from that observable ? the same that is working in html.