rxjs

Returning value from subscription typescript

只谈情不闲聊 提交于 2019-12-21 05:43:07
问题 How would i return success from Save() method. public SaveItem() { if(save()){ // The goal is to use save method like this // Close pop up; } public SaveAndNew() { if(save()){ // The goal is to use save method like this // Create new item; } private save() { let issuccess = false; this.myservice.AddParty(newUserObject) .subscribe(data => { if (data['status'].toString() === '1') { return issuccess = false; } else { return issuccess = true; } }, (er) => { return issuccess = false; }); } If i

How to debug Observable values in Angular2 / Typescript?

点点圈 提交于 2019-12-21 05:17:08
问题 I have followed the tutorial for angular 2 and have a search functionality that renders a list of heroes asynchronously. <div *ngFor="let hero of heroes | async"> {{hero.name}} </div> In the component I have observable heroes: heroes: Observable<Hero[]>; Now I have implemented similar functionality in my application by I don't see anything and I don't see any errors either. I opened the debugger in Chrome and tried to check the value of heroes, but it's just some Observable wrapper of course.

mergeMap does not exist on type observable

若如初见. 提交于 2019-12-21 05:05:03
问题 I am trying to use mergeMap in rxjs6 and i am getting this error: Property 'mergeMap' does not exist on type 'Observable<{}>' I have tried import 'rxjs/add/operator/mergeMap'; and it is not working. What am i doing wrong? import {from, Observable} from 'rxjs'; export class Test { public doSomething(): Observable<any> { return from(...).mergeMap(); } } 回答1: That's correct, the "patch" style of operators has been removed since RxJS 6. You should better update your code to use only "pipeable"

How to better catch/do/empty with RXJS 5.5.2 Updates

独自空忆成欢 提交于 2019-12-21 04:59:14
问题 As staten in the ionic-angular 3.9.0 release notes (https://github.com/ionic-team/ionic/blob/master/CHANGELOG.md), using the advantages of updating to RXJS 5.5.2 could reduce the bundle size and therefore lead to a faster boot time Cool, cool, cool :) The example provided by Ionic, to migrate for example debounceTime is pretty clear, I get it. But it's pretty unclear to me how I should update my following code to take the full advantage of this RXJS update. Anyone could help me to convert it

How to use Rx.Observable.prototype.let operator?

放肆的年华 提交于 2019-12-21 03:30:26
问题 The example and explanation of the let operator (https://github.com/Reactive-Extensions/RxJS/blob/master/doc/api/core/operators/let.md) is not clear. Anyone has a good example/explanation how the let operator works, and when we should use it? 回答1: &tldr; It is a convenience function for being able to compartmentalize logic and inject it into a pipeline. Longer Explanation The source is probably the most definitive explanation. It is really just passing a function which gets called with a

how do I debounce the @Output of an inner component?

点点圈 提交于 2019-12-20 16:38:56
问题 I have a component that wraps another component <inner-component> and binds to the InnerComponent.innerChanged() custom event. I want to bubble up using an @output property, but I also want to debounce the output. How do I use RxJS .debounce() or .debounceTime() to do this? Something like this: import {Component, Output, EventEmitter} from 'angular2/core'; import 'rxjs/add/operator/debounce'; import 'rxjs/add/operator/debounceTime'; @Component({ selector: 'debounced-component', template: `

how do I debounce the @Output of an inner component?

隐身守侯 提交于 2019-12-20 16:38:09
问题 I have a component that wraps another component <inner-component> and binds to the InnerComponent.innerChanged() custom event. I want to bubble up using an @output property, but I also want to debounce the output. How do I use RxJS .debounce() or .debounceTime() to do this? Something like this: import {Component, Output, EventEmitter} from 'angular2/core'; import 'rxjs/add/operator/debounce'; import 'rxjs/add/operator/debounceTime'; @Component({ selector: 'debounced-component', template: `

create Observable<T> from result

与世无争的帅哥 提交于 2019-12-20 11:03:15
问题 I am trying Angular2. I noticed that the http service use Observable object instead of Promise (I don't like much that choice.. async / await are arriving). In my service, I download a list of Plants from the webservice. Clicking on a plant I show the details using the routing. But in this way when I go back, the plants are downloaded again (because the constructor is called again). To avoid this I want to do something like: public getPlants(): Observable<Plants[]> { if (this._plants != null)

How to catch an error on a Request, then open a modal, then retry when modal closes with RxJS

淺唱寂寞╮ 提交于 2019-12-20 10:46:15
问题 I want to make a call to a server that can return an authorization fail (401) with Angular2's HTTP class. The flow of the request should look like that: The user makes a request to the server with myService.getSomething().subscribe() If the server returns a 401: open a modal window asking the user for his credentials. The user successfully log back into the application The modal closes and executes a callback The callback should retry the initial request (myService.getSomething().subscribe())

Fetch data once with Observables in Angular 2

倖福魔咒の 提交于 2019-12-20 10:42:06
问题 I have a service, what is used several times from a lot of my Angular 2 components. It fetches customer data from a Web API and returns an Observable: getCustomers() { return this.http .get(this.baseURI + this.url) .map((r: Response) => { let a = r.json() as Customer[]; return a; }); } I inject this service in my root component, and in every component that wants to access the customers I just subscribe to that Observable: this.customerService.getCustomers().subscribe(v => this.items = v);