rxjs

Angular 6 observables - extract data from .subscribe() function and use it elsewhere

我的未来我决定 提交于 2021-02-07 03:27:51
问题 I'm banging my head against the wall with observables. Almost all of the documentation I can find is in the older rxjs syntax. I have an API call which is an observable. I'm calling it elsewhere and subscribing to it - trying to populate a table with the data from this GET request. If I simply console.log my getData function, it logs the subscription rather than my data. I can successfully console.log data within the .subscribe function, but I want to use data outside of .subscribe() . How do

Angular 6 observables - extract data from .subscribe() function and use it elsewhere

谁说我不能喝 提交于 2021-02-07 03:25:36
问题 I'm banging my head against the wall with observables. Almost all of the documentation I can find is in the older rxjs syntax. I have an API call which is an observable. I'm calling it elsewhere and subscribing to it - trying to populate a table with the data from this GET request. If I simply console.log my getData function, it logs the subscription rather than my data. I can successfully console.log data within the .subscribe function, but I want to use data outside of .subscribe() . How do

Angular 6 observables - extract data from .subscribe() function and use it elsewhere

廉价感情. 提交于 2021-02-07 03:24:21
问题 I'm banging my head against the wall with observables. Almost all of the documentation I can find is in the older rxjs syntax. I have an API call which is an observable. I'm calling it elsewhere and subscribing to it - trying to populate a table with the data from this GET request. If I simply console.log my getData function, it logs the subscription rather than my data. I can successfully console.log data within the .subscribe function, but I want to use data outside of .subscribe() . How do

Angular 2: Cannot find name 'Subscription'

寵の児 提交于 2021-02-06 14:29:29
问题 When trying to set the type of an attribute I get the error Cannot find name 'Subscription' . From which package do I import it from? import { Component, OnDestroy, OnInit } from '@angular/core'; import { ActivatedRoute, Router } from '@angular/router'; // I'm missing an import here. Just don't know which package to load from. @Component({ moduleId: module.id, selector: 'my-component', templateUrl: 'my.component.html', styleUrls: ['my.component.css'] }) export class MyComponent implements

How to change value in subscription? using rxJS

最后都变了- 提交于 2021-02-05 11:58:27
问题 im creating a timer, and need your help im just learning angular & rxJS and i have some question about this Im creating a timer which have start,stop,pause,reset and btn reset must 'pause' my timer to 300ms how to do it? :D my start timer fnc startTimer() { this.intervalStream$ = interval(1000); this.sub = this.intervalStream$ .subscribe((value) => { this.subscribeTimer = this.convertSeconds(this.timeLeft - value); this.currentTime = this.timeLeft - value; }); } and after this start i have

Unit testing that items get filtered out of Observable (Jasmine/RxJS)

北战南征 提交于 2021-02-05 05:30:07
问题 I'm doing unit testing with Jasmine/Karma against an Angular service. I'd like to confirm that my service properly filters items. For example, if I have a service to get people over a certain age, it should return people over the minimum age (positive case) should NOT return people under a the minimum age (negative case) It's #2 that I'm struggling to test. The service: getPeople(minAge: number): Observable<string> { const source = Observable.from([ { name: 'Joe', age: 30 }, { name: 'Frank',

Why is my RxJS countdown clock not displaying?

两盒软妹~` 提交于 2021-02-04 21:41:54
问题 I am working on an Angular 9 quiz app and I'm using RxJS for the countdown timer (in containers\scoreboard\time\time.component.ts) and the timer doesn't seem to be displaying. The stopTimer() function should stop the timer on the number of seconds on which it is stopped. The timer should stop after the correct answer(s) are selected and the timer should reset in between questions. The time elapsed per question should be saved into the elapsedTimes array. Please see my code for the timer in

angular using an observable within an observable

一世执手 提交于 2021-02-04 21:32:44
问题 I am making an expense manager webapp with angular 6. My database is on firebase. I am using the angularfire2 lib to retrieve and update the data. the database is designed as follows the function to get a category is getCategory(uid:String,categorykey:string):Observable<any> { return this.afdb.object(`users/${uid}/categories/${categorykey}`) .snapshotChanges() .pipe(map(c=>({key:c.payload.key,...c.payload.val()})));} the function that returns observable with an array of expenses is

angular using an observable within an observable

ⅰ亾dé卋堺 提交于 2021-02-04 21:32:35
问题 I am making an expense manager webapp with angular 6. My database is on firebase. I am using the angularfire2 lib to retrieve and update the data. the database is designed as follows the function to get a category is getCategory(uid:String,categorykey:string):Observable<any> { return this.afdb.object(`users/${uid}/categories/${categorykey}`) .snapshotChanges() .pipe(map(c=>({key:c.payload.key,...c.payload.val()})));} the function that returns observable with an array of expenses is

how to access variable of subscribe block of behaviour subject outside the block

孤街浪徒 提交于 2021-01-29 22:10:05
问题 I am using behaviour subject and subscribe it in ts file. trying to access the variable outside the subject block in ts file.. code for service.ts private messageSource = new BehaviorSubject<any>(null); constructor( private apiService: ApiService ) { } // try sendMessage(value: any) { this.messageSource.next(value); } get getMessage() { return this.messageSource.asObservable(); }``` now in TS file ngOnInit() { // this.viewUser = this.commonService.getMessage; this.subscription = this