rxjs

Angular CanActivate With Login Dialog

陌路散爱 提交于 2019-12-24 20:32:32
问题 I have an AuthGuard in which I want to use a login material2 dialog with it. So before canActivate returns, the login dialog is shown and if the login is successful then the dialog returns true so then canActivate returns true as well. If the login is not successful, then the dialog does not return anything and tries again. I have already implemented the dialog in a component and its working fine, I'm looking for help on how to integrate it with the canActivate guard. @Injectable() export

How to handle errors using rxjs and promises?

末鹿安然 提交于 2019-12-24 20:12:30
问题 I am making a http request to a backend api. I have deliberately changed the url to one that returns a 503 so that i can properly handle errors. However the 503 error response is not being returned here . const requestOptions = { url: "https://httpstat.us//503", method: "get", // raxConfig: retryConfig, }; const $metrics = defer(() => from(axios(requestOptions)))); const metrics = await $metrics.pipe( map((val: any) => { if (val.data.metrics.length === 0) { throw val; } return val; }),

Angular Observable Array Object Conversion

廉价感情. 提交于 2019-12-24 19:58:51
问题 So I've read numerous questions on SO about item conversions in Javascript/Angular but am not finding anything that addresses my issues. I'm pulling from Firestore as an object that can have copies. I then need to convert the object using a 1 to many conversion. The object coming from Firestore is a 'MultipleCard'. This 'MultipleCard' has a property called 'copies' which will be used to signify how many 'Cards' should get created. postsCol: AngularFirestoreCollection<MultipleCard>; posts:

Angular 5 chain service observables then return observable to component

我的梦境 提交于 2019-12-24 19:30:09
问题 I have two rest calls I need to make. Rest call 2 depends on rest call 1. And I want to store each result in the service before proceeding. Then I want to return an observable to the component that calls rest call 1 so the component can subscribe in case of issues. code from service: login(username: string, password: string): Observable<AuthAccess> { // rest call 1 return this.getAuthClient() .flatMap(res => { this.client = res.body; // rest call 2 return this.authenticate(username, password)

INTERNAL ASSERTION FAILED: AsyncQueue is already failed

十年热恋 提交于 2019-12-24 19:29:45
问题 I have used promise inside the subscribe/observable as shown below. But it gives errors. can you tell me how to construct or design the code properly here? async loginWithGoogle(): Promise<void> { const result = await this.afAuth.auth.signInWithPopup(new firebase.auth.GoogleAuthProvider()); const userId: string = result.additionalUserInfo.profile.id; const userProfile: AngularFirestoreDocument<UserProfile> = this.fireStore.doc(`userProfile/${userId}`); const userProfiles:

Loop For on a BehaviorSubject stream

泪湿孤枕 提交于 2019-12-24 19:17:44
问题 My thread variable contains 3 different elements. I want to create a For loop that iterates on these three objects. threads: BehaviorSubject<{[key: string]: Thread }> = new BehaviorSubject({}); Here is my function: searchUser(): Observable<Thread> { this.searchArrayThreads = []; let element = document.getElementById('chat-window-input'); return this.threads.map((threadDictionary: {[key: string]: Thread}) => { for( let key in threadDictionary ) { console.log("key", threadDictionary[key]); if

Cancel request using redux observable is not working

谁都会走 提交于 2019-12-24 18:55:17
问题 I'm trying to add in canceling in my request using redux-observable. Trying to implement a simple login example. Currently, I am unable to submit the login request again after I added the cancelation. const loginUserApiCall = (username, password) => { return new Promise((resolve, reject) => { if (username === "foo" && password === "foo") { resolve({ user: { name: "foo", lastName: "fooLName", email: "foo@gmail.com" } }); } reject({ err: "Creds are incorrect" }); }); }; const loginRequestEpic =

AsyncPipe initial value null only if subscription is not shared

若如初见. 提交于 2019-12-24 18:34:58
问题 Given a template that looks like something like this <some-component *ngIf="someColdObservable$ | async" [result]="someColdObservable$ | async" ></some-component> and an observable that looks like this: someColdObservable$: this.store.pipe( select(isAllowedToDoThis), filter(Boolean), flatMap(() => apiRequest()) ); The someColdObservable$ gets subscribed to twice (as expected), which in turn issues two api calls (this is obviously a code smell, but let's disregard that at the moment). In this

How to clean/clear cache of a SubjectReplay instance in rxjs?

醉酒当歌 提交于 2019-12-24 18:33:50
问题 I have a SubjectReplay and I would like to reset it to no cache values so after this reset the next subscriber doesn't get the history? Example new subject replay subject.next(1) reset subject <- this question subject.subscribe() // should NOT receive 1 how can I do this? I need the subject to be the same instance. 回答1: You may look at using a combination of special values and filter operator to get something close to what you are trying to achieve. Let's make a simple case. You want to

How to use frokJoin of Observable with own event

你。 提交于 2019-12-24 17:47:59
问题 Im using Subject of reactivex in my angular2 app to signal event. When I do something like that: let subject1 = new Subject<string>(); let subject2 = new Subject<string>(); subject1.subscribe(data=>console.debug(data)); subject2.subscribe(data=>console.debug(data)); subject1.next("this is test event1"); subject2.next("this is test event2"); everything works fine, but I want to wait for both events to fire, then do some actions. I found Observable.forkJoin but I cant make it work with Subjects