rxjs5

ForkJoin Issue on angular

隐身守侯 提交于 2021-02-19 05:44:18
问题 I make this code for test forkJoin but it does not work! Can you check what is the problem? const observables = []; observables.push(new Observable(subscriber => subscriber.next('Hello'))); observables.push(new Observable(subscriber => subscriber.next(' '))); observables.push(new Observable(subscriber => subscriber.next('World') )); observables.push(new Observable(subscriber => subscriber.next('!'))); forkJoin(observables).subscribe(word => console.log(word.join(''))); 回答1: Try this const

What is the benefit of using observable in Angular 5 http requests?

只谈情不闲聊 提交于 2021-02-19 05:12:18
问题 I am confused about using httpclient in angular 5.I am new to angular and just following the official angular tutorial.I dont know much about observables,promise,pipe etc..Currently I am having a service for handling all the http methods.For post request I am using with pipe.Below is the method. create(model: any,URI) :Observable<Object>{ return this.http.post(API_URL+URI, model) .pipe( catchError(this.handleError('create', model)) ); } private handleError<T> (operation = 'operation', result?

Angular2: How to subscribe to Http.post observable inside a service and a component properly?

纵然是瞬间 提交于 2021-02-18 22:10:25
问题 For a JWT authentification, I make a post request to get the token using the new Http module working with Observables now. I have a simple Login component showing the form: @Component({ selector: 'my-login', template: `<form (submit)="submitForm($event)"> <input [(ngModel)]="cred.username" type="text" required autofocus> <input [(ngModel)]="cred.password" type="password" required> <button type="submit">Connexion</button> </form>` }) export class LoginComponent { private cred: CredentialsModel

Angular2: How to subscribe to Http.post observable inside a service and a component properly?

本秂侑毒 提交于 2021-02-18 22:10:02
问题 For a JWT authentification, I make a post request to get the token using the new Http module working with Observables now. I have a simple Login component showing the form: @Component({ selector: 'my-login', template: `<form (submit)="submitForm($event)"> <input [(ngModel)]="cred.username" type="text" required autofocus> <input [(ngModel)]="cred.password" type="password" required> <button type="submit">Connexion</button> </form>` }) export class LoginComponent { private cred: CredentialsModel

Pausing and resuming an observable stream, please suggest better options

有些话、适合烂在心里 提交于 2021-02-05 06:52:09
问题 I have a requirement to listen to a stream of items from an observable. When certain conditions arise an asynchronous task will be performed on the item and the component will be 'busy' until this completes. I would like to pause handling items in the subscription until this task has completed (as the processing of the following items is dependent on the result) and then resume from the next item in the sequence without any loss. the next part is probably best read whilst looking at the Plunk

RxJS - How to incrementally increase the delay time without using interval?

可紊 提交于 2021-01-20 09:24:30
问题 I want to incrementally increase the delay for this: const source = from(839283, 1123123, 63527, 4412454); // note: this is random const spread = source.pipe(concatMap(value => of(value).pipe(delay(1000)))); // how to incrementally increase the delay where the first item emits in a second, the second item emits in three seconds, the third item emits in five seconds, and the last item emits in seven seconds. spread.subscribe(value => console.log(value)); I'm aware of using interval to

Angular 5 RxJs concatMap,switchMap,mergeMap which?

末鹿安然 提交于 2020-12-13 05:35:31
问题 I have this method to get token via localstorage, if token is not exist or is expired, I will call API to get another token and store to localstorage. In this case, which map should I use, currently using mergeMap, or other way to do this? public doGetToken():Observable<Token> { return this.loadToken().pipe( //get via localstorage map(token=>{ let valid = this.validateTokenIsValid(token); let data = { token: token, valid: valid }; return data; }), mergeMap(data=>{ if (!data.valid) { return

Why would I use RxJS interval() or timer() polling instead of window.setInterval()?

依然范特西╮ 提交于 2020-11-30 06:30:18
问题 Use case: Call a function every minute (60000 ms) that dispatches store action to fetch lastUpdated status of items, which upon response and filtering, updates the store, and updated store is read as an observable and displayed in the view). This needs to happen for as long as the web app is open (so indefinitely). Currently, I'm using this: this.refreshDate = window.setInterval( () => this.store.dispatch(new FetchLastUpdate()) , 60000); And when view is destroyed/dismounted, I delete the

Why would I use RxJS interval() or timer() polling instead of window.setInterval()?

家住魔仙堡 提交于 2020-11-30 06:28:57
问题 Use case: Call a function every minute (60000 ms) that dispatches store action to fetch lastUpdated status of items, which upon response and filtering, updates the store, and updated store is read as an observable and displayed in the view). This needs to happen for as long as the web app is open (so indefinitely). Currently, I'm using this: this.refreshDate = window.setInterval( () => this.store.dispatch(new FetchLastUpdate()) , 60000); And when view is destroyed/dismounted, I delete the

Why would I use RxJS interval() or timer() polling instead of window.setInterval()?

江枫思渺然 提交于 2020-11-30 06:28:47
问题 Use case: Call a function every minute (60000 ms) that dispatches store action to fetch lastUpdated status of items, which upon response and filtering, updates the store, and updated store is read as an observable and displayed in the view). This needs to happen for as long as the web app is open (so indefinitely). Currently, I'm using this: this.refreshDate = window.setInterval( () => this.store.dispatch(new FetchLastUpdate()) , 60000); And when view is destroyed/dismounted, I delete the