angular2-observables

Compare most recent values from multiple BehaviorSubjects

﹥>﹥吖頭↗ 提交于 2019-12-11 17:55:43
问题 Say I have this: isMatchedCountLessThanTotalCountMessage(){ // I want to implement this // "returns" a string asynchronously } getMatchedEventsCount() { return this.dcs.matchCount.asObservable(); } getTotalEventsCount() { return this.dcs.totalCount.asObservable(); } matchedCount and totalCount are like so: public matchCount = new BehaviorSubject<number>(0); public totalCount = new BehaviorSubject<number>(0); these Observables fire integers as values change. Anytime a value is fired from

Subscribing to Observable not triggering change detection

烈酒焚心 提交于 2019-12-11 17:03:27
问题 I am using 'angular2-virtual-scroll' to implement load on demand. The items used to be driven by observable's using the async pipe triggered by the parent component. Now i am trying to call my service from the child. The call is successful and i get my data, i need to use the subscribe event to apply other logic. The issue is change detected does not appear to be working when i update my arrays in the subscribe function. I have read other similar issues but i have had no luck finding a

Angular6 - Read response body of text/plain

浪子不回头ぞ 提交于 2019-12-11 15:19:18
问题 I am performing a sign-up action and in my backend when the user successfully registers I return his id e.g. "105" and when the register fails (user already exists) I return "USER_EXISTS". I have checked the request on Postman and the body of the response is correct. In both cases, I return "plain/text". However, I am not able to find how to get the body of the response through the Observable object that I get return. In register.component.ts: userExists = ""; onSubmit() { const newUser :

Angular 5 nested http client observables return object

五迷三道 提交于 2019-12-11 11:04:09
问题 I am trying to create an observable response where I make one http call and then before returning the response, I make another http call to populate the return object of the first call as shown below. getOrderWithItems(orderId: string, includes: Set<OrderInclude>): Observable<OrderDto> { return this.getOrder(orderId, includes) .map(order => { this.searchItems().subscribe( items => { order.items = items.results; return order; } ) }); } The compiler gives an error: Type 'Observable' is not

How to get data from asObservable()

依然范特西╮ 提交于 2019-12-11 09:00:08
问题 this my service code, let the service name be setGetContext _params: Subject<any> = new Subject<any>(); getParameters(): Observable<SearchContext> { return this._params.asObservable(); } setParameters(search: SearchContext) { this._params.next("Test"); } In the other component i'm trying to get the value of params. this.setGetContext.getParameters().subscribe((data) => { console.log(data); }) Here I'm not getting data and the code is not even triggered. 回答1: The service: public _params:

Angular, subscribe on an array is not working

十年热恋 提交于 2019-12-11 08:02:18
问题 I am doing an alert.service. My service is containing an Array of a Model called Alert. Here is the alert.service @Injectable() export class AlertService { private queue: Alert[] = new Array<Alert>(); constructor() { } getInstance() : Observable<Alert[]> { return of(this.queue); } push(type: string, title: string, message: string) { let alert = new Alert(type, title, message); this.queue.push(alert); window.setTimeout(_ => { this.pop(); },3000); } pop() { this.queue.pop(); } } From my alert

Observable.prototype.concatAll does not seem to yield expected result

杀马特。学长 韩版系。学妹 提交于 2019-12-11 00:34:04
问题 With this code in mind: const Rx = require('rxjs'); var i = 3; const obs = Rx.Observable.interval(10) .map(() => i++) .map(function(val){ return Rx.Observable.create(obs => { obs.next(val) }); }) .take(10) .concatAll(); obs.subscribe(function(v){ console.log(v); }); I would have expected the logged result to be something like: [3,4,5,6,7,8,9,10,11,12] That is, 10 values, starting with 3. However, all we get is just 3 Does anybody know why that would be? 回答1: concatMap will wait for the first

Handling Sending Two Parameters in an API Call in Angular App

三世轮回 提交于 2019-12-10 23:15:35
问题 I have a series of filter functions that allow a user to click on a series of filters in order to filter data displaying in a grid view. I have the filters working using observables when I build them using an individual function for each filter. We are using a kind of query built into mongoose that lets you pass a specific query by field in the body of a post call. I am using it like this: onFilterReceived(language) { if (language) { this.filtersService.getByFilter(this.page, this.pagesize, {

handling observables when one is dependent on data from another

烈酒焚心 提交于 2019-12-10 15:47:49
问题 When one observable runs it is depedent on data which comes from another obseravble and I can't work out how to hanlde this dependency correctly. One observable gets data from Firebase and by subscribing it creates a simple number array called novelsRead: Array The other observable gets a response from an api and by subscribing it is meant to filter out all the records who's ids are present in novelsRead[]. The issue is, when a response comes from the api, novelsRead[] is still empty because

RxJS Map array to observable and back to plain object in array

≯℡__Kan透↙ 提交于 2019-12-10 15:38:37
问题 I have an array of objects from which I need to pass each object separately into async method (process behind is handled with Promise and then converted back to Observable via Observable.fromPromise(...) - this way is needed because the same method is used in case just single object is passed anytime; the process is saving objects into database). For example, this is an array of objects: [ { "name": "John", ... }, { "name": "Anna", ... }, { "name": "Joe",, ... }, { "name": "Alexandra", ... },