我有一个角度提供程序,用于维护登录用户的配置文件 . 因此,应用程序中的几乎所有其他组件都需要订阅用户配置文件以获取用户的名称,订阅状态等 . 配置文件本身的提取方式如下:

private _profile: Observable<any>;
constructor(private afAuth: AngularFireAuth, private afDB: AngularFirestore) {

this.afAuth.authState.subscribe(user => {
  this._user = user;
  console.log('App Auth - user: ', user);

  if (user) {
    this._profile = this.afDB.doc(`/users/${this._user.uid}/`).valueChanges();
    this._profile.subscribe(user => {
      console.log('Profile Changed: ', user.profile);
      this._subbed = !!user.profile.sub;
    });
  }
});

}

然后我想使用rxjs(6)共享运算符将_profile共享给其他订阅者:

getUserProfile(): Observable<any> {
    return this._profile.share();
  }

这样我就不会为这个提供商的每个其他订阅维持一个开放的订阅 .

当我从rxjs /运算符导入共享并尝试在_profile observable上使用它时,我收到一个错误:

Property 'share' does not exist on type 'Observable'