angular2-observables

Is there a benefit to using forEach instead of subscribe with a keyboard input event observable?

前提是你 提交于 2021-02-08 06:29:13
问题 I'm trying to find confirmation if I should prefer to use .forEach instead of .subscribe when I want to listen in on Angular's FormControl.valueChanges observable. FormControl API In Angular's Documentation for forms they use .forEach without really explaining why and say you don't really need to understand it. Document Link I also know from this answer that .forEach will bundle a sort of finite duration of events/incoming values into a promise. So I tried to test both .forEach and .subscribe

Merge Two Dependent API Calls in Angular with Observables/RxJS

别等时光非礼了梦想. 提交于 2021-02-08 05:10:29
问题 Say I have two API calls that return JSON: rows: { {"row": 1, detailId: "a"} {"row": 2, detailId: "b"} } rowDetails: { details: { this row details } } I need to get rows, then loop through each row object getting the detailId to make another call to rowDetails, and attach the details to the row object. The final structure needs to be emitted like so: { {"row": 1, "detailId": a, "details": { row details}} {"row": 2, "detailId": b, "details": { row details}} } In angular 1 I would use q

RxJS - switchMap not emitting value if the input observable is empty array

岁酱吖の 提交于 2021-02-07 07:32:11
问题 I have the setup where I query firebase for list of user favourite posts. Basically, at first I query for user likes and then for each like get the corresponding post - all in one observable sequence. The problem arises when user dislikes the only left post. In that case (when the likes array becomes empty) nothing is fired from the observable and view is not updated (there is always at least one post present). On the one hand, this behaviour seems logical and understandable, but on the other

Use of EventEmitter in service of Angular6

廉价感情. 提交于 2021-01-28 06:43:08
问题 Why Event Emitter can't use in service in angular 6? In Angular documentation they mentioned, "Use in directives and components to emit custom events" 回答1: Because in services all waht you have to do is manipulating data, if you want to notify the data changes you can use Subjet or BehaviorSubjet . EventEmitter is generally used to notify changes from child to parent and as said is supposed to be used only for @Output . please take a look at this link 来源: https://stackoverflow.com/questions

Angular 6 - compare two observables lengths

纵然是瞬间 提交于 2021-01-27 07:34:46
问题 Is there a way to compare the current length of two observables? EDIT: It is to compare the arrays withing the observables. I want to compare all the elements count withing them(See example below). At the point I am trying to do it, they are already completely loaded. Not waiting on any data. For example I want to do: if (array1.length < array2.length) { array1.foreach(item => item.isSelected = true); I tried using pipe, map, tap , but they resolve after some time and don't work for me. I

Angular 6 - compare two observables lengths

时光毁灭记忆、已成空白 提交于 2021-01-27 07:29:09
问题 Is there a way to compare the current length of two observables? EDIT: It is to compare the arrays withing the observables. I want to compare all the elements count withing them(See example below). At the point I am trying to do it, they are already completely loaded. Not waiting on any data. For example I want to do: if (array1.length < array2.length) { array1.foreach(item => item.isSelected = true); I tried using pipe, map, tap , but they resolve after some time and don't work for me. I

Observable from <button> click event in Angular2

浪尽此生 提交于 2020-11-30 02:58:52
问题 What's the preferred way to create an observable from a button's onclick event using Angular 2? I'm not sure if it's considered best practice to grab the native element from the DOM in the component code (how do I do this?), or if there's some other shortcut I don't know about. 回答1: You can use Observable.fromEvent like explained in Angular2 RxJS getting 'Observable_1.Observable.fromEvent is not a function' error Or just forward to an observable like private obs = new Subject(); public obs$ =

Angular 2 Unit Testing Observable Errors (HTTP)

怎甘沉沦 提交于 2020-01-21 07:11:34
问题 I am trying to write unit tests for my API service but have some trouble catching HTTP errors. I am following this guide along with the Angular2 docs since the guide is (slightly) out of date in some minor areas. All unit tests pass apart from those where an error is thrown by the service (due to error HTTP status code). I can tell this by logging out response.ok . From what i've read this has something to do with the unit tests not executing asynchronously, hence, not waiting for the error