rxjs

How to send Multiple Http request sequentially in Angular

北战南征 提交于 2020-01-25 10:10:32
问题 I have written below code to call an API each time before post request happens, First API gets called and the second one is not getting called public post(postUrl: string, model: any): Observable<any> { return this.validateTokenStatus().pipe(map(response => { console.log('response', response); // if (response) { console.log('response2', response); const url = `${environment.webApiUrl}/${postUrl}`; this.spinnerService.start(); console.log('response21', response); return this._http.post(url,

How to send Multiple Http request sequentially in Angular

心不动则不痛 提交于 2020-01-25 10:10:02
问题 I have written below code to call an API each time before post request happens, First API gets called and the second one is not getting called public post(postUrl: string, model: any): Observable<any> { return this.validateTokenStatus().pipe(map(response => { console.log('response', response); // if (response) { console.log('response2', response); const url = `${environment.webApiUrl}/${postUrl}`; this.spinnerService.start(); console.log('response21', response); return this._http.post(url,

How to avoid multiple HttpInterceptor calls while navigating between RxJS mergeMap?

假装没事ソ 提交于 2020-01-25 09:20:08
问题 I'm using two JWT tokens - Refresh Token(expires after 7 days) and Access Token (expires after 15 min). They are stored on httpOnly cookies and can be accessed via server. Refresh methods signs new token and store it on a cookie. I need to check if these tokens are expired after every request like this: @Injectable() export class AuthInterceptor implements HttpInterceptor { constructor(private authService: AuthService, private cookieService: CookieService) { } intercept(req: HttpRequest<any>,

Angular, ngrx - problem with infinitive loop in selector

ⅰ亾dé卋堺 提交于 2020-01-25 08:39:05
问题 There is possible to dispatch action in selector in one store? this.store$.pipe(select(selectPersonByName, {personSelectorProps: this.id[]0})) .subscribe(history => { this.store$.dispatch(selectAssignWorkHistory({historyArray: history})); }); } When I run that code, I have infinitive loop. Dispatch action refresh the store, and re-run selector and so on... 回答1: If this action meant to be fired once upon subscribing to the store selector, you may chain the above statement the RxJS take()

Waiting for observable to finish - Angular

送分小仙女□ 提交于 2020-01-25 08:28:05
问题 I'm using Angular and Firebase storage to upload images and I'm having the problem where my urlImg it's undefined when I try to print it in the console.log inside of the tap . this.snapshot = this.snapshot = this.task.snapshotChanges().pipe( finalize(() => { this.storage .ref(path) .getDownloadURL() .subscribe(url => { this.urlImg = url; // with this you can use it in the html }); }), tap(snap => { if (snap.bytesTransferred === snap.totalBytes) { // Update firestore on completion //Code to

My Subject is not working properly in Angular

前提是你 提交于 2020-01-25 06:41:07
问题 I've created a subject in service file as usual editLectures = new Subject<Lecture>(); getEditLectureListener() { return this.editLectures.asObservable(); } From one component I'm sending a data (I am getting proper data when I console.log it) onUpdate(lec: any) { this.attendanceService.emitLecture(lec); } On another component I'm listening to the Subject: this.updateLecture = this.attendanceService.getEditLectureListener().subscribe(result => { // my code // on console.log(result) i am not

Update visibility of HTML element through directive

这一生的挚爱 提交于 2020-01-25 04:19:28
问题 I have a directive that shows or hides an HTML element StackBlitz : <div *authorize="'A'"> Visible when letter is A </div> And the Authorize directive is: @Directive({ selector: '[authorize]' }) export class AuthorizeDirective implements OnInit { letter: string; @Input() set authorize(letter: string) { this.letter = letter; } constructor(private element: ElementRef, private templateRef: TemplateRef<any>, private viewContainer: ViewContainerRef, private authorizationService:

ngrx/store state not updating in reducer function called

痴心易碎 提交于 2020-01-25 00:48:27
问题 I am starting to add ngrx(8.4.0) to an existing Angular(8.2) application but one of my actions (see action below) when triggered does not mutate state. auth.actions.ts (partial) export const loginSuccess = createAction( '[SIGN IN] Login Success', props<{ user: any; isNewUser: boolean }>() The loginSuccess action is handled by the reducer function below. auth.reducer.ts (partial) export interface AuthState { user: any; isNewUser: boolean; } export const initialState: AuthState = { user: null,

rxjs: how to order responses via Observables

心不动则不痛 提交于 2020-01-24 17:44:25
问题 I am using socket.io to send a series of responses to my front-end. The responses are intended to be sequential, but depending on the connection created by socket.io they're not always guaranteed to come in the correct order (https://github.com/josephg/ShareJS/issues/375). Assuming each response had a sequence field that held a number (shown as the number in the picture above), the observable should emit these responses in order. If a response is received out of order and a certain amount of

error in canActivate guard method

天大地大妈咪最大 提交于 2020-01-24 12:34:19
问题 Below is my implementation of CanActivate guard clause in TypeScript , when I compile this code , it shows below error A function whose declared type is neither 'void' nor 'any' must return a value canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot):boolean { this.appService.isValidUser().subscribe({ next: (data) => data.authenticated, // this return true or false error: (err) => false }); } What is the reason for this error ? 回答1: canActivate should return an Observable