英文:
Type 'Subscription' is missing the following properties from type 'Observable<EnumValue[]>' : source, operator, lift, subscribe, and 3 more
问题
I'll provide a translation of the code and error message without any additional content:
在将Observable<EnumValue[]>
分配给Observable<EnumValue[]>
时出现问题。
fetchContactLocationStates()
{
this.contactLocationStates$ = this.enumValues$
.pipe(takeUntil(this.destroy$))
.subscribe(x => x.filter((p) => p.CategoryId === EnumCategory.State));
}
错误:
类型 'Subscription' 缺少类型 'Observable<EnumValue[]>' 的以下属性:source、operator、lift、subscribe 等 3 个属性。
英文:
Have issues assigning an Observable<EnumValue[]>
to Observable<EnumValue[]>
.
fetchContactLocationStates()
{
this.contactLocationStates$ = this.enumValues$
.pipe(takeUntil(this.destroy$))
.subscribe(x => x.filter((p) => p.CategoryId === EnumCategory.State));
}
Error:
> Type 'Subscription' is missing the following properties from type 'Observable<EnumValue[]>' : source, operator, lift, subscribe, and 3 more.
答案1
得分: 2
contactLocationStates$
期望值为 Observable<EnumValue[]>
。 不应调用 .subscribe()
。
import { map } from 'rxjs';
fetchContactLocationStates()
{
this.contactLocationStates$ = this.enumValues$
.pipe(
takeUntil(this.destroy$),
map((x) => x.filter((p) => p.CategoryId === EnumCategory.State))
);
}
英文:
contactLocationStates$
expects the value of Observable<EnumValue[]>
. You shouldn't call the .subscribe()
.
import { map } from 'rxjs';
fetchContactLocationStates()
{
this.contactLocationStates$ = this.enumValues$
.pipe(
takeUntil(this.destroy$),
map((x) => x.filter((p) => p.CategoryId === EnumCategory.State))
);
}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论