Angular 为什么我在执行RxJS tap()运算符后尝试订阅一个可观察对象时会出现此错误?
我正在使用Firebase FireStore数据库开发一个Angular应用程序,在尝试使用RxJS时遇到以下问题。我会尽力向你解释我想做什么 我只是将此服务方法定义到服务类中:Angular 为什么我在执行RxJS tap()运算符后尝试订阅一个可观察对象时会出现此错误?,angular,typescript,rxjs,rxjs-observables,Angular,Typescript,Rxjs,Rxjs Observables,我正在使用Firebase FireStore数据库开发一个Angular应用程序,在尝试使用RxJS时遇到以下问题。我会尽力向你解释我想做什么 我只是将此服务方法定义到服务类中: getPatientAesteticEvaluationData(patientUID): Observable<AestheticEvaluation> { return this.firestore.collection('aesthetic-evaluation') .doc(p
getPatientAesteticEvaluationData(patientUID): Observable<AestheticEvaluation> {
return this.firestore.collection('aesthetic-evaluation')
.doc(patientUID)
.valueChanges()
.pipe(
map(aestheticEvaluation => !!aestheticEvaluation ? aestheticEvaluation : {}),
tap(console.log)
)
}
我试图调用前一个服务方法以检索返回的可观察对象。
然后,我尝试访问此对象的内容,以便调用Fill美学评估表单(美学评估数据)传递这些数据
目前,这是我的Fill美学评估表单()方法中唯一的代码:
fillAestheticEvaluationForm(aestheticEvaluationData) {
console.log("fillAestheticEvaluationForm START !!! aestheticEvaluationData: ", aestheticEvaluationData);
}
问题是这样做永远不会调用此方法。我认为我必须订阅返回的可观测数据,但如果我尝试这样做:
this.patientAestheticEvaluationData$ = this.patientService.getPatientAesteticEvaluationData(this.patientUID)
.pipe(
tap(aestheticEvaluationData => !!aestheticEvaluationData ? this.fillAestheticEvaluationForm(aestheticEvaluationData) : null),
tap(console.log)
).subscribe();
我在上获取了一个错误。PatientAtheticEvaluationData$:
ERROR in src/app/features/patient/patient-details/aesthetic-evaluation/aesthetic-evaluation.component.ts:24:5 - error TS2740: Type 'Subscription' is missing the following properties from type 'Observable<AestheticEvaluation>': _isScalar, source, operator, lift, and 6 more.
24 this.patientAestheticEvaluationData$ = this.patientService.getPatientAesteticEvaluationData(this.patientUID)
src/app/features/patient/patient details/american evaluation/american evaluation.component.ts:24:5错误TS2740:类型“Subscription”缺少类型“Observable”中的以下属性:\ isScalar、source、operator、lift等6个。
24 this.PatientEsteticEvaluationData$=this.patientService.GetPatientEsteticEvaluationData(this.patientUID)
怎么了?我错过了什么?如何修复此代码?如果订阅了Observable,则不再返回Observable,而是订阅,您需要订阅组件中的Observable,或者干脆不返回任何内容并将返回类型声明为void
ERROR in src/app/features/patient/patient-details/aesthetic-evaluation/aesthetic-evaluation.component.ts:24:5 - error TS2740: Type 'Subscription' is missing the following properties from type 'Observable<AestheticEvaluation>': _isScalar, source, operator, lift, and 6 more.
24 this.patientAestheticEvaluationData$ = this.patientService.getPatientAesteticEvaluationData(this.patientUID)