[英]How to fix the error observable in angular
I want to remove the current user that login thats why I used filter to.我想删除登录的当前用户,这就是我使用过滤器的原因。 but I get an error which is:
但我收到一个错误:
Type 'Subscription' is missing the following properties from type 'Observable[]>': _isScalar, source, operator, lift, and 6 more.
类型 'Subscription' 缺少类型 'Observable[]>' 中的以下属性:_isScalar、源、运算符、提升等 6 个。
Here's the code:这是代码:
@Select(UserPageState.get('collection')) users$: Observable<Array<Partial<User>>>;
async ngOnInit() {
const USER = this.creds.credentials['id'];
this.users$.subscribe(param => param.filter(x => x.id !== USER));
await this.store.dispatch(new UserPageList({ start: 1, length: this.pageSize })).toPromise();
}
HTML HTML
<ag-grid-angular
style="width: 100%; height: 100%;"
[class]="(darkMode$ | async) ? 'ag-theme-balham-dark' : 'ag-theme-balham'"
[gridOptions]="gridOptions"
[rowData]="users$ | async"
[columnDefs]="columnDefs"
[frameworkComponents]="frameworkComponents"
(gridReady)="onGridReady($event)"
(firstDataRendered)="onFirstDataRendered($event)"
>
</ag-grid-angular>
The issue is in below statement, subscribing to an observable returns an Subscription instance and you are again assigning it to observable.问题出在下面的语句中,订阅一个 observable 会返回一个 Subscription 实例,而您又将它分配给了 observable。
this.users$ = this.users$.subscribe(param => param.filter(x => x.id !== USER));
Just don't assign it to observable again, it will resolve the issue.只是不要再次将它分配给 observable,它会解决问题。
this.users$.subscribe(param => param.filter(x => x.id !== USER));
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.