observable

Angular 2 - Using Observables in a component to emit values to other components

ぃ、小莉子 提交于 2019-12-11 13:56:36
问题 I am wondering if it is possible to use Observables in components, and which other components can subscribe to? BugListComponent - component is injected in the boot.ts file where I load all my services (where boostrap is located) import {Subject, BehaviorSubject} from 'rxjs/Rx'; viewBugList$: Subject<boolean>; constructor() { this.viewBugList$ = new BehaviorSubject<boolean>(false); } // Called from template, sends in 'true' private enableIEview(enable: boolean) { if(enable) { this.viewBugList

Making api calls from inside forEach for every element and getting values in Angular using Observable

风格不统一 提交于 2019-12-11 13:45:25
问题 I want to iterate through an array and want to make subsequent api calls , and to display that elements related value currentRefValue: any = []; myArray.droppeditem = []; somearray.forEach(element => { let objTemp:any = {} objtemp.receivedValue = someFunction(element.elementId,element.elementName) myArray.droppeditem.push(objTemp); }) someFunction(eId,ename){ let parentObj = this.getExisitingParentObj(eId); let parentEquip = parentObj.map(equip => equip.entities.filter(entity => entity

Periodically updating Observable value in Angular2

霸气de小男生 提交于 2019-12-11 13:37:29
问题 I'd like to hit and display every 5 seconds from a http link, and it seems to be that using angular2, an observable would be the way to go? getPhaseVotes(issue: string) { return this.http.get(this.URL + 'issue/' + issue + '/getPhaseVotes') .subscribe(data => this.phase_votes = data.json(), err => console.log(err), () => this.getStatus(issue)); } How should I be updating this every 5 seconds? 回答1: You could use the interval operator of Observable : @Injeactable() export class SomeService {

CanJS Observable and dots in keys

人走茶凉 提交于 2019-12-11 12:27:31
问题 My problem is while using canJS Observable I can't use dots in object keys, because can think that some nesting available here. So let's say if I create new observable: var obs = new can.Observe( { "div.test-class": { "color": "#000000;" } } ); can fails with message can.Observe: Object does not exist And I can't create observable using just var obs = new can.Observe( { ".test-class": { "color": "#000000;" } } ); because now can fails with the following error: TypeError: current._set is not a

Subscriber OnComplete called twice

妖精的绣舞 提交于 2019-12-11 10:09:45
问题 Why is the #onComplete() called twice even though the #addSomething() is called only once? This the code snippet: private void addSomething() { Subscriber<AddCommentResponse> subscriber = createSubscriber(); NetworkService.getIp() .subscribeOn(Schedulers.io()) .flatMap(addSomethingService) .subscribeOn(Schedulers.io()) .observeOn(AndroidSchedulers.mainThread()) .subscribe(subscriber); } private Subscriber<AddCommentResponse> createSubscriber() { return new Subscriber<AddCommentResponse>() {

How to guarantee the continuity of observable stream in case of http errors?

北战南征 提交于 2019-12-11 09:50:19
问题 I have a problem with the below method ( onTrySignin ) when I encounter an HTTP error response. The catch block right after my HTTP call prevents the Side Effect from throwing an Action error. if I do console.log I get this error. TypeError: You provided 'undefined' where a stream was expected. You can provide an Observable, Promise, Array, or Iterable. how can I preserve the Observable stream and pass the response to the next block ( mergeMap ) where I can fire other Actions , ( FailedSignin

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 observable array, populated by an http request and manually added data

孤者浪人 提交于 2019-12-11 08:58:35
问题 I'm trying to get my head around observables in Angular 6, but I'm new to anything more recent than AngularJS and seriously struggling right now. I think I've gone through every tutorial I can find and searched extensively here, so hopefully I'm not missing anything, but happy to take friendly pointers... What I'm trying to do is this: GET request to a backend API, returns a JSON array of items , and display that array in a component as a data list Allow a second component to POST new item s

How to unsubscribe or dispose an interval observable on condition in Angular2 or RxJS?

拈花ヽ惹草 提交于 2019-12-11 08:56:10
问题 I'm new to the whole Rx thing and reactive programming, however I have to deal with such a situation. I want a interval observable to check a hardware's status by a POST request to its REST API every 500ms to see if the response changes. So once it changes, I want such interval observable POST request shut down immediately, leaving resource to other future operations. Here is a piece of code. myLoop(item_array:number[], otheroption : string){ for (let item of item_array){ //set hardware

Angular2: Nested Observables in Guard

不问归期 提交于 2019-12-11 08:54:57
问题 I have a Guard protecting a certain route. In the canActive method I need to make two http requests, at which the second one is triggered based on the response of the first one. However, the second request is never made and I assume it is about the nested construct of returning Observables. 1 canActivate(route: ActivatedRouteSnapshot, 2 state: RouterStateSnapshot) : Observable<boolean>|boolean { 3 return this.provider.getA().map( 4 dataA => { 5 return this.provider.getB().map( 6 dataB => { 7