rxjs

unable to show username in angular

偶尔善良 提交于 2019-12-08 12:07:21
问题 i have implemented authentication using jwt tokenization and after login I want to display username on the navbar, but it is not showing anything and giving error on console "ERROR TypeError: Cannot read property 'username' of undefined" but after refreshing the page it is showing the username and still giving the same error on the console. Here is my code NavbarComponent.ts import { Component, OnDestroy } from '@angular/core'; import { AuthService } from '../../services/auth.service'; import

rxjs. is it good practice to have code in subscribe method?

孤人 提交于 2019-12-08 11:56:04
问题 I remember once upon a time I found a recommendation to avoid any code in subscribe method and use pipes instead. // suppose bad observable.subscribe(() => dosmg()) // suppose good observable .pipe(tap(() => dosmg())) .subscribe() The reasoning was related to tree shaking. The second option prompted to be better optimizable. Nowadays I can not find this recommendation anymore as well as the opposite recommendation. And lots of learning materials I encountered are adding the code in the

Reset timer after event in angular 2

假装没事ソ 提交于 2019-12-08 11:39:42
问题 I am implementing logout after 15 mins idle session without using 3rd party lib or ngrx. I have created a service: run(){ window.onload = () => {this.startTimer()}; window.onmousemove = () => {this.resetTimer()}; } startTimer(){ let ticks = Observable.timer(0, 1000); return ticks } resetTimer(){ // code here } sessionTimeOut(){ // logic to logout this.resetTimer().subscribe(val =>{console.log(val)} } I have create few approach using some rxjs functions, none of them has worked so far, Is it

Observable.of(array) updates every time setInterval is fired

 ̄綄美尐妖づ 提交于 2019-12-08 10:04:54
问题 I’m having some weird behaviour when using Observable.of(array) and angular’s async pipe. Maybe I’m using it wrong but I can’t understand it. I have a view.html and view.ts file in Ionic 3 (angular 4). I’m doing a Observable.of(items). Items is just an array with objects. And in my view I have: let item of items | async. It all works great but when I also do a setInterval in the view.ts every 1000 miliseconds... the view updates every 1000 miliseconds. Even when the setInterval doesn’t do

Chaining dependent Observables in RxJs

浪子不回头ぞ 提交于 2019-12-08 08:47:29
问题 What is "best practices" for chaining a sequence of HttpClient calls (assume the current call depends on the results of the previous calls)? The following solution is functional but apparently not recommended. Each get returns an Observable. Use of the "pipe" operator preferred in solution (the newer approach in RxJs). ngOnInit() { this.firstService.get().subscribe((first) => { this.secondService.get().subscribe(second => { this.thirdService.get().subscribe(third => { ... possibly more nested

NGRX Effects how to pass parameter to withLatestFrom operator

大兔子大兔子 提交于 2019-12-08 08:26:27
问题 I am struggling with passing parameter to selector when by using withLatestFrom, which was mapped earlier from load action payload loadLocalSubServices$: Observable<Action> = this.actions$.pipe( ofType(LocalSubServiceTemplateActions.LocalSubServicesTemplateActionTypes.LoadLocalSubService), map((action: LocalSubServiceTemplateActions.LoadLocalSubService) => action.payload.globalSubServiceId), // and below I would like to pass globalSubServiceId withLatestFrom(this.store.pipe(select

Angular4 - how to make CanDeactive guard using dialogService confirmation work with chained observables?

老子叫甜甜 提交于 2019-12-08 07:59:46
问题 I have a CanDeactive guard based on the Hero app in the official docs. This guard first checks if my component does not need cleanup, and it immediately returns false if so. Otherwise it shows a confirm dialog to the user. The dialog is provided by this service (identical to the docs): import 'rxjs/add/observable/of'; import { Injectable } from '@angular/core'; import { Observable } from 'rxjs/Observable'; /** * Async modal dialog service * DialogService makes this app easier to test by

Get a single document by foreign key in using RxJs and AngularFirestore

有些话、适合烂在心里 提交于 2019-12-08 07:55:34
问题 I've written a query that looks like this: getPaymentByBookingId(id: string): Observable<Payment> { return this.afs.collection<Payment>('payments', ref => ref.where('bookingId', '==', id).limit(1)) .valueChanges() .pipe( flatMap(array => from(array)), first() ); } Where a Payment object has a unique reference to a Booking id. I want to find the Payment for a given ID. This seems like quite a convoluted way to right this query. Is there a simpler way to do this - including if there is a code

Keep list updated with Ionic 2 / Angular 2

本小妞迷上赌 提交于 2019-12-08 07:33:50
问题 I have an application developed with Ionic 2 that uses Angular 2. I want to update the list of my component in two ways. Automatic - Refresh if there is no update or if the last update was more than 30 minutes ago. Manual - If the user does not want to wait until the next update, he can update manually at any time. When the user leaves the page cancel the automatic refresh and when he comes back re-initialize. I do not want to update immediately when the user enters the page, but only when it

RxJS wait for second observable then retry original observable on error - TypeScript/Angular 2

人盡茶涼 提交于 2019-12-08 07:26:42
问题 I am fairly new to Angular 2, TypeScript and RxJS and I am creating a simple application that leverages the Salesforce Ajax Toolkit connections library. I am trying to write a handler to catch when a token has expired any time a method from the connections library is called. I have created a service that essentially wraps the connections library to use observables. For example if we look at the insert function I have created my own wrapper function: public insert(object: sforce.SObject):