I have a local variable and want to use the Observable in our Angular Component just to subscribe to it and store the response locally,but some how its getting undefined always.Any clues why its not assigning?
export class ScheduleHistoryComponent implements OnInit, OnDestroy {
subscription: Subscription = new Subscription();
toAccountListDto: any;
constructor(public paymentService: PaymentService) {}
ngOnInit(): void {
this.subscription.add(this.paymentService.getLiteAccountsList()
.subscribe((res: any) => {
this.toAccountListDto = (res.data.accountDtoList);
this.toAccountListDto = this.toAccountListDto.filter(account => account.accountSource.toUpperCase() === 'DDA' ||
account.accountSource.toUpperCase() === 'SVG');
console.log('Inside', this.toAccountListDto); < -- --its prints output here
}, error => {
console.error();
})
);
console.log('Outside', this.toAccountListDto); < -- --its prints output as undefined
}
ngOnDestroy(): void {
this.subscription.unsubscribe();
}
}