我收到以下错误:
EXCEPTION: Cannot find a differ supporting object '[object Object]' in [files | async in Images@1:9]
这是模板的相关部分:
这是我的代码:
export class Images {
public files: any;
public currentPage: number = 0;
private _rawFiles: any;
constructor(public imagesData: ImagesData) {
this.imagesData = imagesData;
this._rawFiles = this.imagesData.getData()
.flatMap(data => Rx.Observable.fromArray(data.files));
this.nextPage();
}
nextPage() {
let imagesPerPage = 10;
this.currentPage += 1;
this.files = this._rawFiles
.skip((this.currentPage - 1) * imagesPerPage)
.take(imagesPerPage);
console.log("this.files:",this.files);
}
}
最后的console.log显示它是一个可观察的:
this.imagesData.getData()从Angular的Http服务返回一个常规的RxJS observable,那么为什么异步管道不能用呢?也许我使用flatMap()的方式是错误的,它会混淆什么?
如果我尝试订阅这样的observable:
this.files = this._rawFiles
.skip((this.currentPage - 1) * imagesPerPage)
.take(imagesPerPage)
.subscribe(file => {
console.log("file:",file);
});
它按预期打印对象列表:
最佳答案
尝试使用Observable< File []>代替:
this.files = this._rawFiles
.skip((this.currentPage - 1) * imagesPerPage)
.take(imagesPerPage)
.map(file => [file])
.startWith([])
.scan((acc,value) => acc.concat(value))
这应该不需要手动代码订阅,并且应该与您当前的模板完美配合.
我在this blog post.做了类似的事情
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。