Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/28.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/typescript/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/maven/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angular 角度7属性';共享';不存在于类型observable中_Angular_Typescript_Rxjs_Angular7 - Fatal编程技术网

Angular 角度7属性';共享';不存在于类型observable中

Angular 角度7属性';共享';不存在于类型observable中,angular,typescript,rxjs,angular7,Angular,Typescript,Rxjs,Angular7,我在Angular 7中编写了CachcingServiceBase,但下面的错误似乎是“可观察的份额不是一个函数” 导入“rxjs/add/operator/share”; 从“rxjs”导入{observeable}; 导出抽象类CachcingServiceBase{ 受保护的缓存(getter:()=>可观察, 设定者:(val:可观察)=>无效, 检索:()=>可观察的):可观察的{ const cached=getter(); 如果(缓存!==未定义){ 返回缓存; }否则{ con

我在Angular 7中编写了CachcingServiceBase,但下面的错误似乎是“可观察的份额不是一个函数”

导入“rxjs/add/operator/share”;
从“rxjs”导入{observeable};
导出抽象类CachcingServiceBase{
受保护的缓存(getter:()=>可观察,
设定者:(val:可观察)=>无效,
检索:()=>可观察的):可观察的{
const cached=getter();
如果(缓存!==未定义){
返回缓存;
}否则{
const val=retrieve().share();
塞特(val);
返回val;
}
}
}

我是否导入了共享运算符错误?我怎样才能解决这个问题。我也尝试以其他方式导入,但无法解决问题

导入错误和使用错误:

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;
    }
  }
从'rxjs/operators'导入{share};
从“rxjs”导入{observeable};
导出抽象类CachcingServiceBase{
受保护的缓存(getter:()=>可观察,
设定者:(val:可观察)=>无效,
检索:()=>可观察的):可观察的{
const cached=getter();
如果(缓存!==未定义){
返回缓存;
}否则{
const val=retrieve().pipe(share());
塞特(val);
返回val;
}
}

}

您使用的是什么版本的rxjs?感谢您的回复下面的回答解决了问题,它是rxjs 6.3.3
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;
    }
  }