如何在 pipe() 在 angularfire 中完成后调用函数
How to call a function after pipe() has completed in angularfire
我有一个非常简单的问题,但它让我沮丧了好几个小时。
我有一个来自 angular firebase 的可观察快照,我正在通过 map 函数管道更改一些数据。
像这样:
this.itemsList = this.itemsRefList.snapshotChanges().pipe(
map(changes =>
changes.map(c => ({
product: c.payload.key,
firmware: c.payload.child('latest').val(),
ref: c.payload.ref,
})
)
)
);
管道完成后我想简单地调用一个函数,我该如何实现?
具体来说,我正在使用 ngx-admin,并且有一张卡片,其内容默认为加载旋转器。
<nb-card>
<nb-card-header>
...
</nb-card-header>
<nb-card-body [nbSpinner]="tableDataLoading" nbSpinnerSize="giant" nbSpinnerStatus="warning">
<div *ngIf="itemsList | async as items">
<ng2-smart-table [settings]="settings" [source]="items"></ng2-smart-table>
</div>
</nb-card-body>
</nb-card>
填充 itemList 后,我想调用一个将 tableDataLoading 设置为 false 的函数,以便微调器消失。
这样做的正确方法是什么,我尝试了很多方法,包括订阅 itemsList,并尝试调用它的函数(告诉我它不是函数),试图看看我是否可以更改html 模板中的变量不知何故 - 无济于事等等
在 changes.map 函数中添加括号。
this.itemsList = this.itemsRefList.snapshotChanges().pipe(
map(changes =>{
let temp = changes.map(c => ({
product: c.payload.key,
firmware: c.payload.child('latest').val(),
ref: c.payload.ref,
}))
//map is done, call other code here
this.callOtherMethodHere();
return temp;
})
);
我有一个非常简单的问题,但它让我沮丧了好几个小时。
我有一个来自 angular firebase 的可观察快照,我正在通过 map 函数管道更改一些数据。
像这样:
this.itemsList = this.itemsRefList.snapshotChanges().pipe(
map(changes =>
changes.map(c => ({
product: c.payload.key,
firmware: c.payload.child('latest').val(),
ref: c.payload.ref,
})
)
)
);
管道完成后我想简单地调用一个函数,我该如何实现?
具体来说,我正在使用 ngx-admin,并且有一张卡片,其内容默认为加载旋转器。
<nb-card>
<nb-card-header>
...
</nb-card-header>
<nb-card-body [nbSpinner]="tableDataLoading" nbSpinnerSize="giant" nbSpinnerStatus="warning">
<div *ngIf="itemsList | async as items">
<ng2-smart-table [settings]="settings" [source]="items"></ng2-smart-table>
</div>
</nb-card-body>
</nb-card>
填充 itemList 后,我想调用一个将 tableDataLoading 设置为 false 的函数,以便微调器消失。
这样做的正确方法是什么,我尝试了很多方法,包括订阅 itemsList,并尝试调用它的函数(告诉我它不是函数),试图看看我是否可以更改html 模板中的变量不知何故 - 无济于事等等
在 changes.map 函数中添加括号。
this.itemsList = this.itemsRefList.snapshotChanges().pipe(
map(changes =>{
let temp = changes.map(c => ({
product: c.payload.key,
firmware: c.payload.child('latest').val(),
ref: c.payload.ref,
}))
//map is done, call other code here
this.callOtherMethodHere();
return temp;
})
);