I'm using .share() to share an Observable among all subscribers to a service:
@Injectable()
export class ChannelsService {
private store: IChannel[] = [];
private _own: BehaviorSubject<IChannel[]> = new BehaviorSubject([]);
readonly own: Observable<IChannel[]> = this._own.asObservable().share();
...(the rest of the service basically makes CRUD http request and then calls this._own.next(result) to emit the result to all subscribers)
}
Problem: Only the first subscription to the Observable (ChannelsService.own.subscribe(...)) is getting initial data, the rest of subscriptions get 'null' as a first subscription's value. Next calls to this._own.next(result) will emit its values to all subscribers properly.
Any idea of how to .share() an Observable among multiple subscribers and get the last value emitted for all the subscribers? (I've tried .share().last() but no way...).
Thanks!