What is the difference between Observable and a Subject in rxjs?

In stream programming there are two main interfaces: Observable and Observer. Observable is for the consumer, it can be transformed and subscribed: observable.map(x => …).filter(x => …).subscribe(x => …) Observer is the interface which is used to feed an observable source: observer.next(newItem) We can create new Observable with an Observer: var observable = Observable.create(observer => … Read more

Property ‘catch’ does not exist on type ‘Observable’

Warning: This solution is deprecated since Angular 5.5, please refer to Trent’s answer below ===================== Yes, you need to import the operator: import ‘rxjs/add/operator/catch’; Or import Observable this way: import {Observable} from ‘rxjs/Rx’; But in this case, you import all operators. See this question for more details: Angular HTTP GET with TypeScript error http.get(…).map is … Read more

Upgrading to Angular 10 – Fix CommonJS or AMD dependencies can cause optimization bailouts

When you use a dependency that is packaged with CommonJS, it can result in larger slower applications Starting with version 10, Angular now warns you when your build pulls in one of these bundles. If you’ve started seeing these warnings for your dependencies, let your dependency know that you’d prefer an ECMAScript module (ESM) bundle. … 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()); } }

Observable Finally on Subscribe

The current “pipable” variant of this operator is called finalize() (since RxJS 6). The older and now deprecated “patch” operator was called finally() (until RxJS 5.5). I think finalize() operator is actually correct. You say: do that logic only when I subscribe, and after the stream has ended which is not a problem I think. … Read more

What is pipe for in RxJS?

The “pipeable” (former “lettable”) operators is the current and recommended way of using operators since RxJS 5.5. I strongly recommend you to read the official documentation on pipeable operators The main difference is that it’s easier to make custom operators and that it’s better treeshakable while not altering some global Observable object that could possible … Read more

RxJS: How would I “manually” update an Observable?

In RX, Observer and Observable are distinct entities. An observer subscribes to an Observable. An Observable emits items to its observers by calling the observers’ methods. If you need to call the observer methods outside the scope of Observable.create() you can use a Subject, which is a proxy that acts as an observer and Observable … Read more

How can I close a dropdown on click outside?

You can use (document:click) event: @Component({ host: { ‘(document:click)’: ‘onClick($event)’, }, }) class SomeComponent() { constructor(private _eref: ElementRef) { } onClick(event) { if (!this._eref.nativeElement.contains(event.target)) // or some similar check doSomething(); } } Another approach is to create custom event as a directive. Check out these posts by Ben Nadel: tracking-click-events-outside-the-current-component selectors-and-outputs-can-have-the-same-name DirectiveMetadata Host Binding

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

node_modules/rxjs/internal/types.d.ts(81,44): error TS1005: ‘;’ expected error after installation of Angular 6

This problem might arise due to version mismatch. To solve your problem you need to do following changes in your package.json file. Step 1 : Go to package.json and modify “rxjs”: “^6.0.0” to “rxjs”: “6.0.0” Step 2 Run npm install in your project. There is no need to change the typescript version. (Mine: “typescript”: “~2.7.2”) … Read more

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