observable

angular2 - Navigate after observable is complete

泄露秘密 提交于 2019-12-18 10:54:51
问题 I have an http observable like so, in my UserService : logout() { return this.http.delete(this.baseUrl + url, { headers: this.headers() }).map((res: IResponse) => { var json = res.json(); json.headers = res.headers; return json; }).subscribe((response) => { //DO SOMETHING, THEN ---- return res; }); } I have created an observable, and created a subscription ( response ) which is the returned success value. Now, in my component, I want to call UserService.logout() and THEN navigate to a new

Events vs Streams vs Observables vs Async Iterators

蓝咒 提交于 2019-12-18 09:54:24
问题 Currently, the only stable way to process a series of async results in JavaScript is using the event system. However, three alternatives are being developed: Streams: https://streams.spec.whatwg.org Observables: https://tc39.github.io/proposal-observable Async Iterators: https://tc39.github.io/proposal-async-iteration What are the differences and benefits of each over events and the others? Do any of these intend to replace events? 回答1: There are roughly two categories of APIs here: pull and

How to pass data from delegate method to the observable's onNext method in RxSwift?

放肆的年华 提交于 2019-12-18 09:53:30
问题 I have manager class which will connect and manage the data and state of the Bluetooth device. The manager class conforms to IWDeviceManagerDelegate and has a method which gives the weight data func onReceiveWeightData(_ device: IWDevice!, data: IWWeightData!) . Once I call listenToWeight() from any controller I want to give the data using Observable. How I fire an onNext event with the data of onReceiveWeightData method to listenToWeight observable? Below is the code. class

AsyncTask replacement with RXJava help needed

ぃ、小莉子 提交于 2019-12-18 05:17:11
问题 I am new to Reactive so go easy on me, but I am trying to replace an async task that is currently run on text changes for an auto suggest function. Below is where I am at with my RX: rest.getMemberList(etSearch.getText().toString())//rest interface .subscribeOn(Schedulers.io()) .observeOn(RxAndroidSchedulers.mainThread()) .subscribe(new Action1<List<Member>>() { @Override public void call(List<Member> results) { ListView ResultsListView = (ListView) findViewById(R.id.list); MemberAdapter =

rxjs flatmap missing

风格不统一 提交于 2019-12-18 01:18:51
问题 I try to chain multiple rx.js observables and pass the data. Flatmap should be the fitting operator but with an import of import { Observable } from 'rxjs/Observable'; it is not found: Error TS2339: Property 'flatmap' does not exist on type 'Observable<Coordinates>' Version 5.0.0-beta.6 of rx.js is used. public getCurrentLocationAddress():Observable<String> { return Observable.fromPromise(Geolocation.getCurrentPosition()) .map(location => location.coords) .flatmap(coordinates => { console.log

fromPromise does not exist on type Observable

一曲冷凌霜 提交于 2019-12-17 23:06:34
问题 In Angular 2 using rxjs I was trying to convert a Promise to Observable. As many of online guides showed I used fromPromise on Observable . Which throws error: Property 'fromPromise' does not exist on type 'typeof Observable'. Observable was imported like: import { Observable } from "rxjs/Observable"; trying to import fromPromise like other operators results in error: import 'rxjs/add/operator/fromPromise'; even if I suppress typescript error it still results in error: (<any>Observable)

Angular CanDeactivate Router Guard with an Observable Subscribed Value

社会主义新天地 提交于 2019-12-17 21:32:05
问题 I've been trying to write a canDeactivate guard to check a saving state from an observable stream and work accordingly. My service goes as this import { Injectable } from '@angular/core'; import { ReplaySubject } from 'rxjs/ReplaySubject'; import { Observable } from 'rxjs/Observable'; @Injectable() export class EditModelService { private savingModelDataSource = new ReplaySubject<boolean>(); savingModelData$ = this.savingModelDataSource.asObservable(); public setSavingModelData(state: boolean)

Loop of subscribes inside a subscribe?

孤街醉人 提交于 2019-12-17 21:21:12
问题 I'm currently struggling with multiples/forEach subscribe inside a subscribe, I'm trying to retreive a list of objects then retreive their images thanks to their ID. Currently I've done this : this.appTypeService.get().pipe( map((apps: AppTypeEntity[]) => { return apps.map((app) => new AppTypeEntity(app)); }) ).subscribe((apps: AppTypeEntity[]) => { apps.forEach((app: AppTypeEntity) => { if (app.Logo != null) { this.appTypeService.getPhoto(app.Id).subscribe((image: string) => { app.Image =

Angular 2 RxJS Observable: RetryWhen filter retry on error Status

一世执手 提交于 2019-12-17 20:28:02
问题 I am using Angular 2 HTTP library which returns an observable. I want to implement retry on certain error status/code. I have an issue, if the error is not 429, Observable.of(error) is getting executed in error case to retry, but when all your 2 retry fails the execution of flow goes to success block instead of catch block. How to make execution of flow to catch block in all retry fails? return this.http.get(url,options) .retryWhen((errors) => { return errors .mergeMap((error) => (error

Property '_body' does not exist on type 'Response'

ぐ巨炮叔叔 提交于 2019-12-17 15:54:23
问题 I am using Angular 2 and getting this error when using an observable Property '_body' does not exist on type 'Response' . The code is below this.securitiesService.getMarketMovers() .subscribe(data => { console.log(JSON.parse(data._body)) }); The getMarketMovers function is simply this: getMarketMovers() { return this._http.get('...url address...') } I have tried to set data to type any but that isn't working for me. The code works and there is definitely a _body property on data but it still