observable

Angular 2 - Show loading-information when (observableData | async) is not yet resolved

旧巷老猫 提交于 2020-06-24 08:12:12
问题 just as the title says, I want to embrace the power of rxjs Observables. What I do now: // dataview.html <div *ngIf="isLoading">Loading data...div> <ul *ngIf="!isLoading"> <li *ngFor="let d of data">{{ d.value }}</li> </ul> // dataview.ts data: any[] = []; isLoading: boolean = false; getData() { this.isLoading = true; this._api.getData().subscribe( data => { this.data = data; this.isLoading = false; }, error => { this.error = error; this.isLoading = false; }); } What I want to do: 1. Use

Angular 2 - Show loading-information when (observableData | async) is not yet resolved

我的未来我决定 提交于 2020-06-24 08:12:01
问题 just as the title says, I want to embrace the power of rxjs Observables. What I do now: // dataview.html <div *ngIf="isLoading">Loading data...div> <ul *ngIf="!isLoading"> <li *ngFor="let d of data">{{ d.value }}</li> </ul> // dataview.ts data: any[] = []; isLoading: boolean = false; getData() { this.isLoading = true; this._api.getData().subscribe( data => { this.data = data; this.isLoading = false; }, error => { this.error = error; this.isLoading = false; }); } What I want to do: 1. Use

How to stop a subscription after the response to a service/store has a certain argument/value [duplicate]

浪子不回头ぞ 提交于 2020-06-17 15:57:07
问题 This question already has answers here : Close subscription on condition with takeUntil() (2 answers) Closed 10 months ago . I have, say a service, or a store selector, to be more accurate, that returns an object that changes after some time (returns a different object). But the thing is, I want to unsubscribe from this service after this object has a certain property in it, or (later) if a property has a certain value to it. I know i'ts usual to use the takeUntil function from 'rxjs', i've

How to use Ionic Data Storage with BehaviorSubject and Observable

≡放荡痞女 提交于 2020-06-17 15:26:26
问题 I'm trying to create app with Angular 9 / Ionic 5 I'm using Ionic Data Storage So, my auth.service.ts looks like: import { Injectable } from '@angular/core'; import { HttpClient, HttpHeaders } from '@angular/common/http'; import { Storage } from '@ionic/storage' import { BehaviorSubject, Observable, from } from 'rxjs' @Injectable({ providedIn: 'root' }) export class AuthService { private currentTokenSubject: BehaviorSubject<string> public currentToken: Observable<string> constructor( private

Recursive function with timeout and check RxJs Observable value polling

牧云@^-^@ 提交于 2020-06-16 17:57:51
问题 I have the recursive function: repeatAlert that is called again if data.answered === null : .... Edit this.repeatAlert(id).subscribe( val => console.log(val)); console.log('1stCall Alert: ', new Date().getMinutes()); .... find(id: number): Observable<any> { return this.http.get(`${this.resourceUrl}ByAlertId/${id}` } repeatAlert(id: number) { this.find(id).subscribe((data: AlertInt) => { if (data.answered === null ) { this.sendNotification('Alert ', data.text); console.log('Call Alert: ', new

Recursive function with timeout and check RxJs Observable value polling

狂风中的少年 提交于 2020-06-16 17:57:50
问题 I have the recursive function: repeatAlert that is called again if data.answered === null : .... Edit this.repeatAlert(id).subscribe( val => console.log(val)); console.log('1stCall Alert: ', new Date().getMinutes()); .... find(id: number): Observable<any> { return this.http.get(`${this.resourceUrl}ByAlertId/${id}` } repeatAlert(id: number) { this.find(id).subscribe((data: AlertInt) => { if (data.answered === null ) { this.sendNotification('Alert ', data.text); console.log('Call Alert: ', new

In a UIViewControllerRepresentable, how can I pass an ObservedObject's value to the view controller and update it every time the values changes?

雨燕双飞 提交于 2020-06-16 05:28:05
问题 I have a UIViewControllerRepresentable struct that is subscribed to an ObservableObject, like this: struct ViewControllerWrapper: UIViewControllerRepresentable { @ObservedObject var chartVM = ChartViewModel() typealias UIViewControllerType = ViewController func makeUIViewController(context: Context) -> ViewController { let lineChartView = LineChartView() let vc = ViewController(lineChartView: lineChartView) return vc } func updateUIViewController(_ uiViewController: ViewController, context:

Best way to chain observable subscriptions in Angular?

半腔热情 提交于 2020-06-14 06:41:07
问题 I have always nested subscriptions when I need to call a resource after getting the result of another one, like so: this.paymentService.getPayment(this.currentUser.uid, this.code) .valueChanges() .subscribe(payment => { this.payment = payment; this.gymService.getGym(this.payment.gym) .valueChanges() .subscribe(gym => { this.gym = gym; }); }); I am using Angular v6 and AngularFire2. Both endpoints (getPayment and getGym) return objects. Is there any more elegant way to do this without nesting

RxJS, Observable, how to preserve value and switch map to another one

这一生的挚爱 提交于 2020-06-11 01:22:11
问题 // ticker$ will update every 3s // showHand$ will only triger after user click button // I would like to take last ticker price as user order price when user click button let lastPrice: number; this.ticker$ // What I am doing now is preserve value to vairable here. .do(ticker => lastPrice = ticker.closePrice) .switchMap(() => this.showHand$) .subscribe(showHand => { // use value here this.order.price = lastPrice; this.order.amount = showHand.amount; this.order.type = showHand.type; this

How to unit test unsubscribe function in angular

[亡魂溺海] 提交于 2020-06-10 02:52:50
问题 I would like to find a way to test unsubscribe function calls on Subscriptions and Subjects. I came up with a few possible solutions, but every one of these have pros and cons. Please keep in mind that I do not want to alter the access modifier of a variable for testing purposes. Accessing private variable of component with reflection. In that case I have a private class variable which stores a subscription: component.ts: private mySubscription: Subscription; //... ngOnInit(): void { this