How to check the length of an Observable array

You can use the | async pipe: <div *ngIf=”(list$ | async)?.length==0″>No records found.</div> Update – 2021-2-17 <ul *ngIf=”(list$| async) as list; else loading”> <li *ngFor=”let listItem of list”> {{ listItem.text }} </li> </ul> <ng-template #loading> <p>Shows when no data, waiting for Api</p> <loading-component></loading-component> </ng-template> Update – Angular Version 6: If you are loading up a … Read more

How to catch exception correctly from http.request()?

Perhaps you can try adding this in your imports: import ‘rxjs/add/operator/catch’; You can also do: return this.http.request(request) .map(res => res.json()) .subscribe( data => console.log(data), err => console.log(err), () => console.log(‘yay’) ); Per comments: EXCEPTION: TypeError: Observable_1.Observable.throw is not a function Similarly, for that, you can use: import ‘rxjs/add/observable/throw’;

Difference between Java 8 streams and RxJava observables

Short answer All sequence/stream processing libs are offering very similar API for pipeline building. The differences are in API for handling multi-threading and composition of pipelines. Long answer RxJava is quite different from Stream. Of all JDK things, the closest to rx.Observable is perhaps java.util.stream.Collector Stream + CompletableFuture combo (which comes at a cost of … Read more

How to create an Observable from static data similar to http one in Angular?

Perhaps you could try to use the of method of the Observable class: import { Observable } from ‘rxjs/Observable’; import ‘rxjs/add/observable/of’; public fetchModel(uuid: string = undefined): Observable<string> { if(!uuid) { return Observable.of(new TestModel()).map(o => JSON.stringify(o)); } else { return this.http.get(“http://localhost:8080/myapp/api/model/” + uuid) .map(res => res.text()); } }

How can I `await` on an Rx Observable?

You have to pass a promise to await. Convert the observable’s next event to a promise and await that. if (condition) { await observable.first().toPromise(); } Edit note: This answer originally used .take(1) but was changed to use .first() which avoids the issue of the Promise never resolving if the stream ends before a value comes … Read more

Delegation: EventEmitter or Observable in Angular

Update 2016-06-27: instead of using Observables, use either a BehaviorSubject, as recommended by @Abdulrahman in a comment, or a ReplaySubject, as recommended by @Jason Goemaat in a comment A Subject is both an Observable (so we can subscribe() to it) and an Observer (so we can call next() on it to emit a new value). … Read more

Angular/RxJS When should I unsubscribe from `Subscription`

TL;DR For this question there are two kinds of Observables – finite value and infinite value. http Observables produce finite (1) values and something like a DOM event listener Observable produces infinite values. If you manually call subscribe (not using async pipe), then unsubscribe from infinite Observables. Don’t worry about finite ones, RxJs will take … Read more

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