@H_502_2@
EXCEPTION: Cannot find a differ supporting object '[object Object]' in [files | async in Images@1:9]
这是模板的相关部分:@H_502_2@
@H_502_2@
![]()
@H_502_2@
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显示它是一个可观察的:@H_502_2@
@H_502_2@
this.imagesData.getData()从Angular的Http服务返回一个常规的RxJS observable,那么为什么异步管道不能用呢?也许我使用flatMap()的方式是错误的,它会混淆什么?@H_502_2@
如果我尝试订阅这样的observable:@H_502_2@
@H_502_2@
this.files = this._rawFiles
.skip((this.currentPage - 1) * imagesPerPage)
.take(imagesPerPage)
.subscribe(file => {
console.log("file:",file);
});
它按预期打印对象列表:@H_502_2@
最佳答案