【发布时间】:2021-10-31 15:11:21
【问题描述】:
我想问你为什么我在 [nzData] 中获取我的 observable 时遇到问题,但如果我在 * nfIF 中获取数据则不是。详细使用这种方法效果很好:
<div *ngIf="visibleAggregate">
<nz-table
id="activitiesTable"
*ngIf="tableData$ | async as Table"
>
<thead>
<tr>
<th *ngFor="let column of Table.columns">
{{ column.label }}
</th>
</tr>
</thead>
</nz-table>
</div>
但是如果我将我的 observable 传递给 nzData,它会告诉我它是不可迭代的。我需要将数据传递给 nzData。 ([nzData]="tableData$ | async")
我以这种方式创建 observable
private groupBySubject = new BehaviorSubject<any>(null);
private groupBy$ = this.groupBySubject.asObservable();
tableData$: Observable<TableData> = combineLatest([
this.database$,
this.groupBy$,
]).pipe(map(([db, sc]) => this.buildTableData(db, sc)));
group(value: Observable<any>) {
this.groupBySubject.next(value);
}
错误:
core.js:6210 ERROR TypeError: listOfData is not iterable
at MapSubscriber.project (ng-zorro-antd-table.js:1742)
at MapSubscriber._next (map.js:29)
at MapSubscriber.next (Subscriber.js:49)
at CombineLatestSubscriber.notifyNext (combineLatest.js:73)
at InnerSubscriber._next (InnerSubscriber.js:11)
at InnerSubscriber.next (Subscriber.js:49)
at BehaviorSubject._subscribe (BehaviorSubject.js:14)
at BehaviorSubject._trySubscribe (Observable.js:42)
at BehaviorSubject._trySubscribe (Subject.js:81)
at BehaviorSubject.subscribe (Observable.js:28)
at subscribeToResult (subscribeToResult.js:9)
at CombineLatestSubscriber._complete (combineLatest.js:52)
at CombineLatestSubscriber.complete (Subscriber.js:61)
at Observable._subscribe (subscribeToArray.js:5)
at Observable._trySubscribe (Observable.js:42)
at Observable.subscribe (Observable.js:28)
我只是想做:
<div *ngIf="visibleAggregate">
<nz-table
#aggregate
id="activitiesTable"
[nzData]="tableData$ | async"
>
<thead>
<tr>
<th *ngFor="let column of aggregate.data">
{{ column.columns.label }}
</th>
</tr>
</thead>
</nz-table>
</div>
我已经将这种方法与其他 Obserables 一起使用,并且它可以工作,甚至从文档中也是如此。 我不明白为什么这个 obserable 只能在显示的第一种模式下工作。
【问题讨论】:
-
应该也写错了。
-
好的,抱歉,完成了!
标签: angular typescript rxjs observable ng-zorro-antd