Category : rxjs

Let’s assume that there is a service will be used for http request calls.And two different components(could be more than two) which will send same request by using same observables via this service.After getting result that should be assigned to global variable(Components have not relationship like parent-child or child-parent).Below I wrote same code block for ..

Read more

In ngOnInit() I have a forEach method that generates some FormGroups with some FormControls. Then, I created an array containing the statusChanges of each FormGroup. ticketsFormArr: FormGroup[] = []; this.tickets.forEach(ticket => { this.ticketsFormArr.push(new FormGroup({ ticketType: new FormControl(”, Validators.required), rods: new FormControl(”, Validators.required), firstName: new FormControl(”, Validators.required), lastName: new FormControl(”, Validators.required), email: new FormControl(”, Validators.required), })) ..

Read more

There are events: const left$ = fromEvent(this.left.nativeElement, ‘mousedown’).pipe( switchMapTo(timer$), mapTo(-1) ); const right$ = fromEvent(this.right.nativeElement, ‘mousedown’).pipe( switchMapTo(timer$), mapTo(1) ); const leftClick$ = fromEvent(this.left.nativeElement, ‘click’).pipe( switchMapTo(timer$), mapTo(-1) ); const rightClick$ = fromEvent(this.right.nativeElement, ‘click’).pipe( switchMapTo(timer$), mapTo(1) ); const rotate$ = merge(left$, right$).pipe( startWith(0), scan((acc, value) => acc + value), map(rotation => rotation * this.rotateAngle) ); As output ..

Read more

There is click stream: const leftClick$ = fromEvent(this.left.nativeElement, ‘click’).pipe(mapTo(-1)); const rotate$ = merge(leftClick$).pipe( tap(e => console.log(e)), startWith(0), scan((acc, value) => acc + value) ); Why do I get two the same messages here: tap(e => console.log(e)), I get two messages: -1, -1 Source: Angular..

Read more