rxjs

Guarantee observable subscription finishes before proceeding to next code

非 Y 不嫁゛ 提交于 2019-12-13 09:07:08
问题 I am doing a bit of a cascade delete with multiple service calls. Some of the later subscriptions rely on previous subscriptions to finish. How can I guarantee an subscription finishes before moving onto my next code? // Need to make sure this code completes data.forEach(element => { this.myService.delete(element.id).subscribe(); }); // Before running this code this.myService.getAll().subscribe(res => { res.data.forEach(element => { this.myService.delete(element.id).subscribe(); }); } ); 回答1:

After getting the response from post api call , an error is thrown => .pipe is not a function

只愿长相守 提交于 2019-12-13 07:57:29
问题 I am making an api call and expecting a response from it which can be passed to 2nd api call but I am getting an error ERROR TypeError: this.helperService.getPointIdbyTags(...)[0].pipe is not a function on line .pipe(switchMap((resarray:any)=>{ TS code someFunction(floor){ floor.entities.forEach(element => { let desiredTempForZone; this.getCurrentValue(element.name).subscribe((des) => { currentTempForZone = des }); console.log(currentTempForZone); }) } getCurrentValue(eleName){ let roomObj =

TypeError: Cannot read property 'something' of undefined. Angular 2

这一生的挚爱 提交于 2019-12-13 07:28:01
问题 i have popular error, TypeError: Cannot read property 'something' of undefined. and my code works But why i should to use *ngIf or async? why it happens? and can i solve this problem without this strange solutions what i describe bellow Sorry but i can not find answer why // service public getEmployee(id) { return this._af.database.object(`/employee/${id}`) .map(response => response) .catch(error => Observable.throw(error.json())); } //component public employee: Employee; ngOnInit() { this

Error handling in Angular2

前提是你 提交于 2019-12-13 07:17:52
问题 I'm working on an Angular 2 service returning data from a restful WebApi backend. I'm trying to make it gracefully handle the service not being available however I'm getting unexpected information in the error responses. Here's the code update(fund, transactionId:string, showToastOnError: boolean, useCorrectUrl: boolean) { let options = this.getStartCall(); options.headers.append("transaction-id", transactionId) let url = fundsUrl + (useCorrectUrl ? "" : "breakTheUrl"); return this._http.put

Angular 2 + RxJS BehaviorSubject subscribe call not working

穿精又带淫゛_ 提交于 2019-12-13 06:46:54
问题 I am trying to build a simple header component which as of now just tries to print the id of the Navigation that is registered inside of it using the subscribe method on a BehaviorSubject inside of a NavService. The NavService registers the Nav and calls the next method on the BehaviorSubject. But the value does not transmit to the header component. All I get is the initial value of the BehaviorSubject. Could you please tell me what I am doing incorrectly? Header Component: @Component({

How do I use .take on FirebaseListObservable?

社会主义新天地 提交于 2019-12-13 06:44:37
问题 If I try to use RxJS operators like .take, .skip, etc. on FireBaseListObservable, I get "take is not a function" error: import {Component} from '@angular/core'; import {AngularFire, FirebaseListObservable} from 'angularfire2'; import {Observable} from 'rxjs'; export class AppComponent { items: FirebaseListObservable<any>; constructor(public af: AngularFire) { // this works Observable.interval(1000).take(5).subscribe(x => console.log(x)); this.items = af.database.list('/items'); // this does

Need a way to subscribe to an observable that Angular service holds and also display it in view

こ雲淡風輕ζ 提交于 2019-12-13 06:35:09
问题 I am writing an angular + nodejs application where server listens to twitter stream and front-end angular application using socket.io gets data from server. Everything works till this point, but I am unable to find a way to subscribe to my angular service which using socket.io gets the data. How can I subscribe to the data that my service has and also how can I bind it to my view, so that the data shows up. Here is my service code in Angular that gets data from server: import {Injectable}

Multiple RxJS AJAX Requests

血红的双手。 提交于 2019-12-13 06:34:11
问题 I'm using rxjs to make several http requests and I want to end up with an object that looks something like: { 100: { ...response from api call... }, 205: { ...response from api call... }, ...etc... } Here's what I have so far: const projectIds = [100, 205, 208, 300] const source = Rx.Observable .from(projectIds) .flatMap(id => get(`projects/${id}/builds`)) .map(response => response['data']) .zip(projectIds) .toArray() source.subscribe(pipelines => { console.log(pipelines) }) This gives me

Piping inside a subscribe in ngrx

喜欢而已 提交于 2019-12-13 06:29:38
问题 I have a selector that takes a parameter to filter values. The parameter depends on an observable's return. export class LineSynopticComponent implements OnInit, AfterViewInit { schedules$: Observable<ISchedule[]>; ngOninit(){ this.selectedDate$.subscribe(elm => { this.schedules$ = this.store.pipe(select(selectSchedulingsTimes, { time: elm.timeSelect })); }); } the selectSchedulingsTimes selector is defined as well: const schedulings = (state: IAppState) => state.schedulings; export const

shareService in angular 2 - twice subscribe the next function

喜欢而已 提交于 2019-12-13 06:29:34
问题 I have a ShareService in angular 2,and in another component i subscribe that,and this is my code : *******ShareService *********************************** private ShopItem$ = new Subject<any>(); ShopItem$_ = this.ShopItem$.asObservable(); public addToCart(item : any){ this.ShopItem$.next(item); } *************in another component********************** _shareService.ShopItem$_.subscribe((item) => { alert("hiii"); <====>this functions execute twice this.ADD_TO_CART(item);<====>this functions