请检查代码:
export class SomePage {
uids:Observable<any[]>;
uamt:Observable<any[]>;
constructor(private db: AngularFireDatabase) {
this.uids = this.db.list('data/request').snapshotChanges().map(changes => {
return changes.map(c => ({ key: c.payload.key, ...c.payload.val() }));
});
}
this.uamt = this.db.list('data/account').snapshotChanges().map(changes => {
return changes.map(c => ({ key: c.payload.key, ...c.payload.val() }));
});
}可能不需要管道?
//some.html
<ion-row *ngFor="let ud of uids | async; let bl of uamt | async">如果我需要添加管道怎么办?
发布于 2017-11-29 06:44:40
ngFor中分号之后的第二部分是获取现有循环的索引,而不是另一个循环。类似于“让uids的uids\异步;让我=索引”之类的东西,然后如果需要的话,可以在组件中使用循环的索引号。
但这不是你想要的,我不这么认为。我不知道“uids”和“uamt”是什么,但听起来好像您想要两个列表中的每一项都有一行。也许你可以:
<ion-row *ngFor="let ud of uids | async"> <ion-row *ngFor="let bl of uamt | async">
或者在组件中,您可以将它们合并成相同的可观察到的,可能是这样的:
class SomePage {
uidsAndUamt: Observable<any[]>;
constructor(private someService: SomeService) {}
ngOnInit() {
this.uidsAndUamt = this.someService.uids.mergeMap(uids => {
return this.someService.uamt.map(uamt => uids.concat(uamt));
})
}
}然后你就可以把这个放在你的html里了:
<ion-row *ngFor="let item of uidsAndUamt | async">我不确定这是不是你要找的。
发布于 2017-11-29 06:55:33
备选案文1
您可以使用ng容器创建嵌套绑定,并且只能选择两个数组位于相同索引上的绑定。
<ng-container *ngFor="let um of umat | async; let i = index">
<ng-container *ngFor="let ui of uids | asnyc; let j = index">
<ion-row *ngIf="i==j">
</ion-row>
</ng-container>
</ng-container>这个选项的问题是,如果这些数组中有许多(100+)项,那么角必须迭代100*100次。因此,对于大型数组来说不是很好。
备选案文2
您可以像这样迭代两个数组。只要你知道他们都有相同的价值观
<ion-row *ngFor="let uid of uids | async; let i=index" >
uid = {{uid}}
uamt = {{uamt_last[i]}}
</ion-row>只要你必须从第二个可观测到的地方填充umat_last
umat.subscribe((data)=>{this.umat_last = dat;});https://stackoverflow.com/questions/47545559
复制相似问题