RXJS Wait for all observables in an array to complete (or error)

If you want to compose an observable that emits when all of the source observables complete, you can use forkJoin: import { Observable } from ‘rxjs/Observable’; import ‘rxjs/add/observable/forkJoin’; import ‘rxjs/add/operator/first’; var tasks$ = []; tasks$.push(Observable.timer(1000).first()); tasks$.push(Observable.timer(3000).first()); tasks$.push(Observable.timer(10000).first()); Observable.forkJoin(…tasks$).subscribe(results => { console.log(results); });

Node.js Streams vs. Observables

Both Observables and node.js’s Streams allow you to solve the same underlying problem: asynchronously process a sequence of values. The main difference between the two, I believe, is related to the context that motivated its appearance. That context is reflected in the terminology and API. On the Observables side you have an extension to EcmaScript … Read more

Angular async pipe and object property [duplicate]

The error is surprisingly accurate as the *ngIf directive expects true or false and uses the resulting expression to determine whether or not to render the HTML element in the DOM. EXCEPTION: Invalid argument ‘true’ for pipe ‘AsyncPipe’ in [!user$.anonymouse | async in SettingsPage@27:22] The expression you have is user$.anonymouse which evaluates as truthy, but … Read more

How to return observable from subscribe

You can’t return an observable from subscribe but if you use map instead of subscribe then an Observable is returned. canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot):Observable<boolean> { // get route to be activated this.routeToActivate = route.routeConfig.path; // get user access levels return this._firebase.isUserAdminObservable .map(user => { // do something here // user.access_level; return true; }) .first(); // … Read more

Best way to import Observable from rxjs

Rxjs v 6.* It got simplified with newer version of rxjs . 1) Operators import {map} from ‘rxjs/operators’; 2) Others import {Observable,of, from } from ‘rxjs’; Instead of chaining we need to pipe . For example Old syntax : source.map().switchMap().subscribe() New Syntax: source.pipe(map(), switchMap()).subscribe() Note: Some operators have a name change due to name collisions … Read more

Child listens for parent event in Angular 2

For the sake of posterity, just thought I’d mention the more conventional solution to this: Simply obtain a reference to the ViewChild then call one of its methods directly. @Component({ selector: ‘app-child’ }) export class ChildComponent { notifyMe() { console.log(‘Event Fired’); } } @Component({ selector: ‘app-parent’, template: `<app-child #child></app-child>` }) export class ParentComponent { @ViewChild(‘child’) … Read more

RxJS sequence equivalent to promise.then()?

For data flow (equivalent to then): Rx.Observable.fromPromise(…) .flatMap(function(result) { // do something }) .flatMap(function(result) { // do something }) .subscribe(function onNext(result) { // end of chain }, function onError(error) { // process the error }); A promise can be converted into an observable with Rx.Observable.fromPromise. Some promise operators have a direct translation. For instance RSVP.all, … Read more

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