I am facing a challenge in returning a value from an observable method to assign it to a public variable for later use. Specifically, I need to retrieve this value and store it in the 'viewcount' variable for utilization in another function.
public viewcount:any;
public getcount(id){
let view = " ";
this.backandService.getViews(id).subscribe(
(data:any) =>{
view = data["0"].views;
console.log(view);
}
);
return view;
}
In another method, I attempt to use the returned value as follows:
public updateViews(id){
let view:any = this.viewcount;
this.backandService.update('videos',id,
{"viewcount":JSON.stringify(view)}).subscribe(
data =>{
console.log(data);
}
);
}
However, despite my efforts, the value is never successfully returned for application in the 'updateViews' method. The console log displays XHR requests indicating a 404 not found error, with the request payload showing an empty bracket.