Error: : fromEvent is not declared writable or has no setter

You need to spy on a property of rxjs. Using spyOnProperty will solve the error. Try this import * as rxjs from ‘rxjs’ import { of, fromEvent } from ‘rxjs’; spyOnProperty(rxjs, ‘fromEvent’).and.returnValue(of({})) you can also add to getter/setters using this like spyOnProperty(rxjs, ‘fromEvent’, ‘get’).and.returnValue(false) Hope this helps

Wait for an async operation in onNext of RxJS Observable

Each operation you want to perform can be modeled as an observable. Even the synchronous operation can be modeled this way. Then you can use map to convert your sequence into a sequence of sequences, then use concatAll to flatten the sequence. someObservable .map(function (item) { if (item === “do-something-async”) { // create an Observable … Read more

Do I need to complete a Subject for it to be garbage collected?

If you look at the source for Subject.complete, you’ll find the answer: complete() { if (this.closed) { throw new ObjectUnsubscribedError(); } this.isStopped = true; const { observers } = this; const len = observers.length; const copy = observers.slice(); for (let i = 0; i < len; i++) { copy[i].complete(); } this.observers.length = 0; } Calling … Read more

How to subscribe to event emitter once?

A call to subscribe returns an instance of Disposable, which has a method dispose. Or if you are using RxJS 5, dispose has been renamed to unsubscribe (thanks @EricMartinez). And from the RxJS docs: …when we’re no longer interested in receiving the data as it comes streaming in, we call dispose on our subscription. Store … Read more

How to implement a debounce time in keyup event in Angular 6

In the component you can do somthing like this. Create RxJS Subject, In search method which is called on keyup event, do .next() on this Subject you have created. Then subscribe in ngOnInit() will debounce for 1 second, as in below code. searchTextChanged = new Subject<string>(); constructor(private http:Http) { } ngOnInit(): void { this.subscription = … Read more

How to handle boolean observables with the async pipe in Angular

Here’s a way where you can share the subscription and not have to make any custom pipe: <ng-container *ngIf=”{value: obs$ | async} as context”> {{context.value}} </ng-container> The *ngIf will evaluate to true no matter what (I believe) and then you can do your own tests on the value in the context object. …would be better … Read more

How to create an RXjs RetryWhen with delay and limit on tries

You need to apply the limit to the retry signal, for instance if you only wanted 10 retries: loadSomething(): Observable<SomeInterface> { return this.http.get(this.someEndpoint, commonHttpHeaders()) .retryWhen(errors => // Time shift the retry errors.delay(500) // Only take 10 items .take(10) // Throw an exception to signal that the error needs to be propagated .concat(Rx.Observable.throw(new Error(‘Retry limit exceeded!’)) … Read more

Emit a single value

A lot of the stuff is tucked away in: import ‘rxjs/Rx’; You might try Observable.of for a single value. This works for me (plunker): import {Component} from ‘angular2/core’; import {Observable} from ‘rxjs/Observable’; import ‘rxjs/Rx’; @Component({ selector: ‘my-app’, providers: [], template: ` <div> <h2>Hello {{test | async}}</h2> </div> `, directives: [] }) export class App { … Read more

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