rxjs

Ionic 2 http.get() issue

半城伤御伤魂 提交于 2019-12-06 07:25:39
I tried to make a http.get() call with these two methods. First: getResults(){ return this.http.get('http://localhost/api.php') .toPromise() .then( data => data.json() ); } Error Shown: 3 122412 error EXCEPTION: Uncaught (in promise): Response with status:0 for URL: null 4 122413 error ORIGINAL STACKTRACE: 5 122413 error Error: Uncaught (in promise): Response with status: 0 for URL: null .......... Second: getResults(){ return new Promise((resolve, reject) => { this.http.get('http://localhost/api.php') .map(res => res.json()) .subscribe(data => { resolve(data); }, (err) => { reject(err); }); }

Angular2 call a Component from a Service

会有一股神秘感。 提交于 2019-12-06 07:18:37
I am trying to call a Method in my Component from a a Service . What is the proper way to do this? I have tried to use rxjs Subject to create an Observable, but I cannot get it to fire. import {Subject} from 'rxjs/Subject'; export class MyService { callComponent = function(value) { let invokeEvent = new Subject(); invokeEvent.next({some:value}) } } and in my Component export class MyComponent { constructor(private _myService: MyService) { this._myService.invokeEvent.subscribe(value => console.log(value)) } } Here's the plunker: http://plnkr.co/edit/WKSurRJMXo5JZOPrwSP5?p=preview Change your

detecting multitouch longpress event using rxjs

旧街凉风 提交于 2019-12-06 07:12:21
问题 Been playing around with rxjs. I find it really good, but it really took some time to get my head around it. Here's a little one I can't solve, so I'm looking for some insight. Consider a multitouch interface where for each touchstart/touchmove/touchend you would have as params an object with {id:, x:x, y:y, t:t, current_pointers: } I would like an observable that would trigger an event for each down pointer after 1500 ms unless touchmove or touchup happens for that pointer. For a single

Using pure Observable vs array (from subscribe)

眉间皱痕 提交于 2019-12-06 07:11:15
I was wondering about best practices regard using pure observable vs subscribe to an observable and use an array. option 1 - "pure observable" this.schools = this.angularFire.database.list('schools') and then in the HTML use async pipe (and rxjs operators for handling the data) option 2 - "subscribe to array" this.angularFire.database.list('schools').subscribe (response => this.schools=response) and then treat it as a normal array. As olsn pointed out in the comments, it is always more practical to use the async pipe to handle this situation. However, if you choose to use the manual subscribe

Angular 2 Observable Interval locks out UI

萝らか妹 提交于 2019-12-06 07:00:02
问题 When I use a Observable.Interval to perform a http refresh of a UI it locks out the buttons on the UI from working if the interval is too fast. The buttons do not register the click, seems to be a timing issue. If I increase the timing and therefore miss the get call the buttons work, but the data is then delayed in updating. Interval this.dataSub = Observable.interval(1000).subscribe(x => { this.getData(); }) getData getData(): void { this.dataService.getData() .subscribe( data => this.data

RxJS Observable with asynchronous subscriber function

若如初见. 提交于 2019-12-06 06:54:24
问题 I'm trying to do something that feels like it should be straightforward, but is proving surprisingly difficult. I have a function to subscribe to a RabbitMQ queue. Concretely, this is the Channel.consume function here: http://www.squaremobius.net/amqp.node/channel_api.html#channel_consume It returns a promise which is resolved with a subscription id - which is needed to unsubscribe later - and also has a callback argument to invoke when messages are pulled off the queue. When I want to

Is ReplaySubject(1) the same as AsyncSubject()?

北慕城南 提交于 2019-12-06 06:38:21
I'm currently using this to perform notifications: /** * Create notifications that broacast * the entire set of entries. */ protected notify = new ReplaySubject<E[]>(1); IIUC I can switch out the ReplaySubject<E[]>(1) with AsyncSubject<E[]>() ? Would this be an apple to apple switch or might here be semantic differences? No, they're very much not the same. ReplaySubject(1) will always replay the latest emission no matter when the observer subscribes. It can emit any number of times. AsyncSubject ignores all emissions until the observable completes, then emits the last emitted value. It can

angular- programmatically close alert when a new alert is triggered

冷暖自知 提交于 2019-12-06 06:38:06
问题 I have two kinds of alerts- secondary alerts and delayed alerts Secondary alert messgaes are shown at first and user has to hit OK button to close it. But there are delayed alerts also..which are triggered by a setTimeout() I'm trying to automatically close secondary alerts when this delayed alert is shown to user I tried to dismiss the secondary alerts like this this.secondaryAlertVar.dismiss(); But it's not working. Here's the code import { Component, OnInit } from "@angular/core"; import *

Poll API using Angular HTTP Observable

时光毁灭记忆、已成空白 提交于 2019-12-06 06:30:10
In my component html, I am using the asyncPipe to subscribe to this http service. The service maps the json response object to an array of class instances. This all works great, but I would like http service to poll every few seconds. I've tried a bunch of things (like interval), but it seems RXJS is a bit of a minefield at the moment. Has anyone implemented this kind of thing using Angular 6? fetch(command, params?) { return this.http.post(`http://localhost:4000/${command}`, params) .pipe( map((data: Data) => { const statuses: Status[] = []; for (const statusKey of Object.keys(data.statuses))

Angular2 NGRX Performance Issues On Dispatch?

故事扮演 提交于 2019-12-06 06:08:40
I've been working on an application in Angular2/CLI/NGRX and things have been going well until recently. I'm noticing some pretty big spikes in performance especially with consecutive dispatches within the same container. For example lets say I have the following defined: public appEnvironment$: Observable<IEnvironment>; public assessment$: Observable<IAssessment>; public assessmentComments$: Observable<ICommentActivity[]>; public assessmentEvidence$: Observable<IEvidenceActivity[]>; public assessmentIssues$: Observable<IIssueActivity[]>; public assessmentSurvey$: Observable<ISurvey>; public