RxJS combineLatest without waiting for source observables to emit?

If I understand correctly you want a pattern like the following diagram: stream1$ => —— 1 —— 12 ———————– stream2$ => ————————- 30 ————- result$ => —— 1 —— 12 —— 42 ————– If one value is available, emit that. If both are available, emit the combination of both, a simple sum in this case … Read more

How to return value inside subscribe Angular 4

You can’t directly return totalQuestions like that, you need to use a subject to achieve that. getTotalQuestions(idForm:string): Observable<string> { let totalQuestions:number; var subject = new Subject<string>(); this.getFirebaseData(idForm+”/Metadatos”) .subscribe(items => { items.map(item => { totalQuestions=item.Total; console.log(totalQuestions); subject.next(totalQuestions); }); } ); return subject.asObservable(); } Usage: getTotalQuestion(idForm).subscribe((r)=>console.log(r))

Angular – DialogRef – Unsubscribe – Do I need to unsubscribe from afterClosed?

No You don’t need to unsubscribe as the observable itself completes.You can verify the same by adding a finalize block to see whether observable completes itself or not. import { finalize } from “rxjs/operators”; dialogRef .afterClosed() .pipe(finalize(() => console.log(“completed”))) .subscribe(data => { console.log(data); }); And when you will close the dialog, you will see completed … Read more

Angular2 RxJS getting ‘Observable_1.Observable.fromEvent is not a function’ error

Its definitly not needed to import all operators at once! You just imported fromEvent wrong. You could do it like this: import {Observable} from ‘rxjs/Observable’; import ‘rxjs/add/observable/fromEvent’; EDIT: In addititon to what I already wrote: tree-shaking with the AoT-Compiler of angular removes unused code, based on what you import. If you just import some objects … Read more

Rxjs Retry with Delay function

delay() is used to introduce a delay between events emitted by the observable. But the observable never emits any event. It just errors immediately. What you’re looking for is retryWhen(), which allows deciding after how long to retry: RxJS 5: .retryWhen(errors => errors.delay(1000).take(10)) RxJS 6: import { retryWhen, delay, take } from ‘rxjs/operators’ someFunction().pipe( // … Read more

Angular/RxJS 6: How to prevent duplicate HTTP requests?

After trying a few different methods, I came across this one that resolves my issue and only makes one HTTP request no matter how many subscribers there are: class SharedService { someDataObservable: Observable<any>; constructor(private http: HttpClient) {} getSomeData(): Observable<any> { if (this.someDataObservable) { return this.someDataObservable; } else { this.someDataObservable = this.http.get<any>(‘some/endpoint’).pipe(share()); return this.someDataObservable; } } … Read more

TypeError: search.valueChanges.debounceTime is not a function

you Just need to import these to remove your error. You are getting runtime error because Observables by default come with just a few operators. You have to explicitly import them like this – import ‘rxjs/add/operator/debounceTime’; import ‘rxjs/add/operator/map’; Working example Update Angular 6 onwards, debounceTime is imported as following – import { debounceTime } from … Read more

Angular 6 router.events.filter ‘filter’ does not exist on type ‘Observable’

This is how to filter router events with Angular 6+ and latest RxJS: import { Component, OnInit } from ‘@angular/core’; import { Router, ActivatedRoute, NavigationEnd } from ‘@angular/router’; import { filter } from ‘rxjs/operators’; export class MyComponent implements OnInit { constructor(private router: Router, private activatedRoute: ActivatedRoute) {} ngOnInit() { this.router.events.pipe( filter(event => event instanceof NavigationEnd) … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)