Reputation: 69
I was writing CachcingServiceBase in Angular 7 but the following error seems to be hit "the observable share is not a function"
import "rxjs/add/operator/share";
import { Observable } from "rxjs";
export abstract class CachcingServiceBase {
protected cache<T>(getter: () => Observable<T>,
setter: (val: Observable<T>) => void,
retreive: () => Observable<T>): Observable<T> {
const cached = getter();
if (cached !== undefined) {
return cached;
} else {
const val = retreive().share();
setter(val);
return val;
}
}
}
am i importing the share operator wrong? how can i solve this ? . I tried to import in other ways too but could not solve the issue
Upvotes: 3
Views: 4417
Reputation:
Wrong import and wrong usage :
import { share } from 'rxjs/operators';
import { Observable } from "rxjs";
export abstract class CachcingServiceBase {
protected cache<T>(getter: () => Observable<T>,
setter: (val: Observable<T>) => void,
retreive: () => Observable<T>): Observable<T> {
const cached = getter();
if (cached !== undefined) {
return cached;
} else {
const val = retreive().pipe(share());
setter(val);
return val;
}
}
}
Upvotes: 10