I want to return value (any data) from service to component as an observable. After a couple of digging into observables found following solution:
class AppService {
getData(value) {
// do we have any other best way to return value as an observable
return Observer.create((observer) => {
observer.next(value);
});
}
}
class AppComponent implements OnInit {
ngOnInit() {
this.dataService$ = this.appService.getData().subscribe((data) => {
// do some task with data
});
}
}
return of(value)