[英]Adding delay in observable returns partial data in Angular rxjs
在我的代碼中,我需要使用timer(500)添加延遲。 但問題是它返回部分數據。 它返回 2 個字段,而實際數據有 17 個字段。 我附上了我的代碼。 請看。 謝謝
返回值:
['booking_display_id', 'edit']
期望值:
['booking_display_id', 'bookingstatus', 'b_contactname', 'member', 'b_emailaddress', 'b_mobilenumber', 'startdate', 'enddate', 'duration', 'bookingguest', 'guestnotes', 'vouchers', 'paypalpaymentpdt', 'totalCost', 'canPay', 'canCancel', 'edit']
this.displayedColumns = combineLatest(this.table.columns.reduce((observables: Observable<boolean>[], col) => { // handle showIf property of column const show = col.showIf(this.injector, this.route.queryParamMap); observables.push(show instanceof Observable ? show : of(show)); return observables; }, []), timer(500)).pipe( map(showCols => { const cols = this.table.columns.filter((c, i) => showCols[i]) .map(c => c.id); this.editEnabled && cols.push('edit'); this.deleteEnabled && cols.push('delete'); console.log('cols', cols) return cols; }) );
您需要合並延遲事件和可觀察事件。
let c = [
'booking_display_id',
'bookingstatus',
'b_contactname',
'member',
'b_emailaddress',
'b_mobilenumber',
'startdate',
'enddate',
'duration',
'bookingguest',
'guestnotes',
'vouchers',
'paypalpaymentpdt',
'totalCost',
'canPay',
'canCancel',
'edit',
];
let bsObs: BehaviorSubject<String> = new BehaviorSubject<String>('');
let obs: Observable<String> = bsObs.asObservable();
obs
.pipe(
concatMap((x) => of(x).pipe(delay(500)))
)
.subscribe((s) => console.log(s));
c.forEach((c) => bsObs.next(c));
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.