How to convert an Observable to a ReplaySubject?

You can use just observable.subscribe(subject) if you want to pass all 3 types of notifications because a Subject already behaves like an observer. For example: let subject = new ReplaySubject(); subject.subscribe( val => console.log(val), undefined, () => console.log(‘completed’) ); Observable .interval(500) .take(5) .subscribe(subject); setTimeout(() => { subject.next(‘Hello’); }, 1000) See live demo: https://jsbin.com/bayewo/2/edit?js,console However this … Read more

Angular2. How can I check if an observable is completed?

You can do this by using onCompleted callback in subscription. For example, let’s say you show loading bar when user press report button; loadCompanies(): void { this._companyService.getCompanies().subscribe( response => { this.companiesModel = response; }, err => { console.log(err); //closeLoadingBar(); }, () => { //do whatever you want //closeLoadingBar() } ) } generateReport() { //showLoadingBar() this.loadCompanies(); … Read more

Observables : Cancel previous http request on new subscription call

I would use a subject to keep everything reactive. In your template html listen to change events and emit a new value to the subject. <searchBar (change)=”search$.next($event.target.value)” /> then in your component: this.subscription = this.search$.pipe( debounceTime(800), distinctUntilChanged(), switchMap(searchText=>http.post(‘api_link’, {searchText}) }).subscribe(response=>{ this.response = response. }); The switchMap will cancel any HTTP request that hasn’t completed if … Read more

RxJs difference between complete and unsubscribe in Observable?

You complete an Observable, and unsubscribe a Subscription. These are two different methods on two different objects. You subscribe to an observable which returns a Subscription object. If you want to stop listening to emits from the Observable you call subscription.unsubscribe(). If you want an Observable to be done with his task, you call observable.complete(). … Read more

How to receive blob responses using Angular’s 2+ @angular/http module?

With the release of Angular2 final we can define for example a service: @Injectable() export class AngularService { constructor(private http: Http) {} download(model: MyModel) { //get file from service this.http.post(“http://localhost/a2/pdf.php”, JSON.stringify(model), { method: RequestMethod.Post, responseType: ResponseContentType.Blob, headers: new Headers({‘Content-Type’, ‘application/x-www-form-urlencoded’}) }).subscribe( response => { // download file var blob = new Blob([response.blob()], {type: ‘application/pdf’}); var … Read more

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