rxjs

Angular 6 Reactive Forms : How to set focus on first invalid input

℡╲_俬逩灬. 提交于 2019-12-09 16:57:58
问题 Under my Angular 6 app , i'm using Reactive Forms . My purpose is when submitting , i want to set focus on first invalid input when error. My form looks like this : <form [formGroup]="addItemfForm " (ngSubmit)="onSubmitForm()"> <div class="form-inline form-group"> <label class="col-md-2 justify-content-start"> Libellé du pef <span class="startRequired mr-1"> *</span> </label> <input type="text" maxlength="100" formControlName="libellePef" class="col-md-6 form-control" placeholder="saisie

How to request data sequentially in Cycle.js?

拥有回忆 提交于 2019-12-09 16:08:07
问题 I’m new to reactive programming and toying around with cycle.js, trying to implement who to follow box from this tutorial. But I understood that for proper implementation (and learning purposes) I don’t have one piece of data: full user name. I can get it by sequentially getting users and then full user data from server. In imperative style I would do something like this: fetch(`https://api.github.com/users`) .then(data => data.json()) .then(users => fetch(users[0].url)) .then(data => data

Get all current (active) subscriptions

老子叫甜甜 提交于 2019-12-09 14:42:48
问题 Is it possible to get all the "active" subscriptions without storing them manually? I'd like to unsubscribe all of the "active" subscriptions and don't want to reference each of them in an array or a variable. 回答1: I depends on whether you're using a Subject or an Observable but there's probably no way to do this "automatically". Observables I don't think you can have such thing as "subscribed Observable" because you either store an Observable or Subscription: const source = Observable.of(...

Debouncing and cancelling with redux-observable

只谈情不闲聊 提交于 2019-12-09 12:09:37
问题 I am trying to create a simple redux-observable epic which debounces and is cancelable. My code: export const apiValidate = action$ => { return action$.ofType(validateRequestAction) .debounceTime(250) .switchMap((action) => ( Observable.ajax({ url: url, method: 'GET', crossDomain: true, headers: { "Content-Type": 'application/json' }, responseType: 'json' }) .map(payload => (new APISuccessValidate())) .takeUntil(action$.ofType(validateCancelAction)) .catch(payload => ([new APIFailureValidate(

How to unsubscribe/stop Observable?

混江龙づ霸主 提交于 2019-12-09 11:18:56
问题 I use the following code for timer: export class TimerService { private ticks: number = 0; private seconds: number = 0; private timer; constructor(seconds: number) { this.seconds = seconds; this.timer = Observable.timer(2000, 1000); this.timer.subscribe(t => { this.ticks = t; this.disactivate(); }); } private disactivate() { if (this.ticks === this.seconds) { this.timer.dispose(); } } } When I try to stop timer in line: this.timer.dispose(); // this.timer.unsubscribe(); It does not work for

Subscribe multiple FormControl(s) only once

佐手、 提交于 2019-12-09 10:15:59
问题 I have filtered out few FormControl(s) from a large FormGroup based on some logic now - I'd like to know how can I merge / combine those selected FormControls and have only one subscribe.. I looked into RxJS docs and marble diagrams but didn't understand it properly. It's very confusing to understand all of these and know which one to use for my case: - forkJoin - combineLatest - merge - join - zip Here's more detailed info about the question: Let's say 2 FormControls (i.e., controlA,

Observable .catch is not a function

牧云@^-^@ 提交于 2019-12-09 09:31:41
问题 I get this very annoying error when running my code from a unix environment. This works fine when I run the code locally through ng serve , But when I deploy the code to my server, this error halts all program execution: ERROR TypeError: this.http.get(...).catch is not a function Google results state that I should import rxjs namespaces straight from their location, and not through the rxjs/Rx bundle, but I get this error regardless. Other results point out that I may have missed importing

Trigger valueChange with Initialized value - angular2

你说的曾经没有我的故事 提交于 2019-12-09 06:42:26
问题 I'm writing an angular2 application and I'm stuck with something. First of all, I have a select which is bind to a formControl : export class MyComponent implements OnInit { profilesBy: Observable<any[]>; myControl = new FormControl(); constructor(public http: Http) { this.profilesBy = this.myControl.valueChanges .map(text => new formatQuery(text.value)) .switchMap(body => this.getGroupBy(body, this.url), (_, res)=> res.json().aggregations.group_by_type.buckets); } } so, myControl is the

Cannot find module 'rxjs/subject/BehaviorSubject'

醉酒当歌 提交于 2019-12-09 05:01:35
问题 I am using Angular 2. When I use either of these two, my program runs well: import { BehaviorSubject } from 'rxjs/Rx'; import { BehaviorSubject } from 'rxjs'; However, I try to use the following way: import { BehaviorSubject } from 'rxjs/subject/BehaviorSubject'; But I failed, my browser console shows: Uncaught Error: Cannot find module 'rxjs/subject/BehaviorSubject' How can I use third way correctly? Thanks 回答1: import {BehaviorSubject} from 'rxjs/BehaviorSubject'; rxjs 6.x import

RxJS parallel queue with concurrent workers?

╄→гoц情女王★ 提交于 2019-12-09 03:25:22
问题 Let's say I want to I download 10,000 files. I can easily build a queue of those 10,000 files (happy to take advice if any of this can be done better), import request from 'request-promise-native'; import {from} from 'rxjs'; let reqs = []; for ( let i = 0; i < 10000; i++ ) { reqs.push( from(request(`http://bleh.com/${i}`)) ) }; Now I have an array of Rx.JS observable I've created from promises that represent my queue. Now for the behavior of what I want, I want to issue Three-concurrent