I have a function like one the below in
service.ts:-
itemList$: BehaviorSubject<any> = new BehaviorSubject([]);
getItem() {
this.http
.get('APIURL Here')
.subscribe((res: any) => {
this.itemList$.next(res.data);
});
}
Below is my component.ts:-
constructor(private myService: MYService) {
}
matchItem(idtomatch:any){
let matchStatus:boolean=false;
this.myService.itemList$.subscribe((res: any) => {
for (let val of res) {
if(idtomatch === res.id){
matchStatus = true;
}
else{
matchStatus = false;
}
}
});
return matchStatus;
}
this.matchItem(idtomatch)
It should return true when idtomatch === res.id else it should return false while it's always returning false.