rxjs

'of' from Observables

和自甴很熟 提交于 2019-12-13 20:18:32
问题 I was doing this tutorial on reactive forms and stumbled on following problem: import { Observable, of } from 'rxjs'; here you should import of from rxjs but when I try to it say's: [ts] Module '"/.../node_modules/rxjs/Rx"' has no exported member 'of'. Also tried import 'rxjs/add/observable/of'; which didn't work either. In the example 'of' is used for following: getHeroes(): Observable<Hero[]> { return of(heroes).pipe(delay(this.delayMs)); // simulate latency with delay } Any suggestions how

How to merge an observable that is a property of another observable

我与影子孤独终老i 提交于 2019-12-13 18:06:51
问题 I have a list of holidays each with a user id attached to them. I would like to merge the retrieved user data to each holiday record so it returns a single observable. I created this function getAllHolidaysAndUsers() { return this.af.database.list('Holiday').mergeMap(items => { for (let item of items) { item.user = this.af.database.object(`/User/${item.userIdKey}`); } return items; }); } it returns an object like this { fromDate:'20/12/16', toDate:'21/12/16', user:fireBaseObservable } I would

Emitting only after set of events?

我们两清 提交于 2019-12-13 18:03:38
问题 I'm trying to do something like the following - B is being emitted independently of A, but I want to emit when there is a B that happens after an A (in that order). ----A--------A--> B--B--B--B----B-> ------B-------B-> Thanks! 回答1: In case you have a hot observable and you want to emit the values from B , then you might want to use a switchMap in combination with a take(1) : (basically just the 3 last lines are relevant, the upper part is just mocking some data-stream) // Mocking A and B

Refresh ag-grid on Observable subscribe

ε祈祈猫儿з 提交于 2019-12-13 17:59:31
问题 I am struggling to refresh ag-grid on subscription of an observable. I have following piece of code which works well. this.marketConfigs = this._regionProductConfigService.getMarketConfig(); this.gridOptions.columnDefs = this.createColumnDefs(); this.gridOptions.rowData = this.marketConfigs; But since I am trying to put a drop-down in columns of ag-grid, I wanted the column config to be created once we receive data. So I changed the code to following : this._refDataService.getAllCurrencies()

Catch in Observable stops HTTP Calls from Observable.interval

Deadly 提交于 2019-12-13 16:36:01
问题 Observable.interval(10000) .switchMap(() => this.http.get(url)) .catch (err => Observable.empty()) .subscribe(data => render(data)) Each 10 seconds we make an HTTP call. If an error happens, observable becomes completed, it doesn't make any calls anymore. How to prevent that? 回答1: That's correct behavior, when a complete or error notification is sent observers unsubscribe and the chain is disposed. You can use the retry() operator to resubscribe but it's hard to tell what is your goal from

Async Pipe Fails to Render Observable

无人久伴 提交于 2019-12-13 16:34:54
问题 e(1): Updated code to address typo's in original question. e(2): Attempted to 'JSON.stringify()' the data pushed into my JSON object in 'createContent()'. No luck. e(3): Added plnkr as requested: http://plnkr.co/edit/j024MYCQbypAGaf762fT I have a model... class Content { constructor(public name: string) { } } I have a service... class ContentService { private _contents$: Subject<Content[]> = new Subject<Content[]>(); get contents$(): Observable<Content[]> { return this._contents$.asObservable

Efficiently get Observable of an array BehaviorSubjects

[亡魂溺海] 提交于 2019-12-13 16:28:33
问题 I have this field: smartArray: BehaviorSubject<BehaviorSubject<object>[]>; //Example [{key1: 'value1', key2: value2},...]; I now want to get and subscribe to one of the properties: getObeservablePropertyOfSmartArray(index, property){ return this.smartArray.pipe( //...getelementAtIndex <---dont know how //lets say the elementatIndex is elem: elem.pipe( //get the property and return the Observable )).asObservable(); } So I basically need the equivalent of array[index] and object[key] and return

How to process RxJS stream n items at a time and once an item is done, autofill back to n again?

狂风中的少年 提交于 2019-12-13 16:24:48
问题 I have a stream of events and I would like to call a function that returns a promise for each of those events, the problem is that this function is very expensive, so I would like to process at most n events at a time. This pebble diagram is probably wrong but this is what I would like: ---x--x--xxxxxxx-------------x-------------> //Events ---p--p--pppp------p-p-p-----p-------------> //In Progress -------d--d--------d-d-dd------dddd--------> //Promise Done ---1--21-2-34-----------3----4-3210-

Property 'interval' does not exist on type 'Observable<any>'

旧城冷巷雨未停 提交于 2019-12-13 16:15:35
问题 I have the following code inside the constructor of my Angular2 component class: Observable.from([1,2,3]).interval(2000).subscribe(e=>{ console.log(e); }); I imported the following: import { Observable } from 'rxjs/Observable'; import 'rxjs/add/observable/from'; import 'rxjs/add/observable/interval'; I have the following error message while building my project using Angulat CLI: Property 'interval' does not exist on type 'Observable<any> What am I missing? 回答1: That's correct. The interval

Rxjs常用的管道操作符

▼魔方 西西 提交于 2019-12-13 16:11:51
map switchMap mergeMap mep 类似于 Array.prototype.map() switchMap switchMap 会停止发出先前发出的内部 Observable 并开始发出新的内部 Observable 的值。(可以停止上一次发出的ajax) mergeMap 将每个值映射到Observable,必须返回一个Observable scan 和 reduce reduce 只返回最后的值 // res: 12, 15 from([2, 3]).pipe( scan((acc, item) => acc += item, 10)) .subscribe(v => console.log(v)) // res: 15 from([2, 3]).pipe( reduce((acc, item) => acc += item, 10)) .subscribe(v => console.log(v)) filter 和 partition filter 返回你想要的数据 partition 返回两个 Observables [0] 符合断言, [1] 不符合断言 from([2, 3, 4]).pipe( filter(item => item <= 3)) .subscribe(v => console.log(v)) pairwise()