我正在尝试通过使用管道ListView
来填充基本信息。BehaviourSubject
async
标记代码非常简单:
组件.html
<ListView [items]="$photos | async" separatorColor="transparent">
<ng-template let-item="item">
<Label>{{ item.upid }}</Label>
</ng-template>
</ListView>
接下来在我使用的组件中push
ChangeDetectionStrategy
,订阅负责数据检索和填充的服务BehaviourSubject
。以下是相关代码:
组件.ts
user: ComunicationModels.UserDto = {};
photos: Array<ComunicationModels.PhotoDto> = [];
$photos: BehaviorSubject<Array<ComunicationModels.PhotoDto>>;
constructor(...) {
this.$photos = new BehaviorSubject([]);
this.user.photos.forEach(
(idPhoto) => {
this.postService.getPhoto(idPhoto)
.subscribe((p) => {
this.photos.push(p);
this.$photos.next([...this.photos]);
// console.dir(this.$photos.value); -> This shows correct information
});
});
}
我没有收到错误,但我的列表视图完全是空的,没有显示任何项目......我错过了什么?