Questions tagged observable

Explore the latest questions and answers asked by our top developers.

How to test polling with rxjs timer?

I have an angular component in which I made a polling in ngOnInit using rjxs timer, like this: ngOnInit() { timer(0, 60000). subscribe(() => { this.getSomeStuff(); } } In jest I have a spy on the function: const getSomeStuff = jest.spyOn( component, ‘getSomeStuff’ ); My goal is to test how many time the "getSomeStuff" function […]

By Emanuele
Published
Categorized as angular, jestjs, observable, rxjs, timer Tagged , , , ,

@Ionic5/angular12 – @Input + Modal + nested components – Details Non-Changing on parent

so here is the problem: I have a nested component app-request-short which triggers a Modal, which if button clicked, changes the "request.status" from pending to scheduled; when the modal is dismissed, the app-request-long parent of the previous one, should update the list ordering without refreshing the page (actually when the page refreshes it changes the […]

how to wait for response request Angular

I am trying to create a validator for one of the fields in my form. This validator is created in a service, however, to create it I must make a get request that returns the value with which my validator must match, but since the server’s response does not occur instantly when returning the value, […]

By pete
Published
Categorized as angular, observable, typescript Tagged , ,

Angular map wait Observable to complete

I am trying to send httpclient in my Observable function, it will run without the HttpClient Complete. Here is a demo code which is used to reproduce test() { this.test2() .pipe( mergeMap((result) => { console.log(result[0]); return of([]); }) ) .subscribe(); } test1(): Observable<any> { return of(this.getStudents()); } test2(): Observable<any> { return this.test1().pipe( mergeMap((result) => { […]

By Edward
Published
Categorized as angular, httpclient, observable, rxjs, typescript Tagged , , , ,

Convert an observable to an array or modify functions working with observable

I use the following code to calculate the average of the attempts of all successfully completed experiments from the specified array. The code works for the specified array. The problem is now that the interface does not provide an array but an observable. The structure of the observable I add below. What can I do […]

By Jonas960
Published
Categorized as angular, observable, rxjs Tagged , ,

Observable can’t pass in finally from err state

Is not first time when I encounter this problem. Because I want to display some data on web page, even if the http request failed, I have some logique inside the err state. To not duplicate code in subscribe and err, I use to write it inside complete/finally state. this.loadingResults = true; this.service.get().subscribe(data => { […]

By AlleXyS
Published
Categorized as angular, observable, rxjs, subscribe, typescript Tagged , , , ,

Remove item from Observable<any[]> Angular autocomplete with dropdown

I have implemented autocomplete research in my Angular project. I am now trying to remove the list from the dropdown when option is selected. Problem is I am getting my data async so my data is a stream and I am not sure how to remove the object from the stream. Any help is welcome: […]

By LaCodeM
Published
Categorized as angular, observable, rxjs5, typescript Tagged , , ,

How can I use my variable as an observable?

I have a service with a selectedLanguage variable, but I got a null value instead of the real value data: any = {}; selectedLanguage = ‘en’; constructor(private http: HttpClient, private storage: Storage) { } async use(lang: string): Promise<{}> { lang = lang ? lang : await this.storage.get(‘lang’); return new Promise<{}>((resolve) => { const langPath = […]

By alexx0118
Published
Categorized as angular, observable, rxjs Tagged , ,

RxJS sequential delay between emissions

I have a Observable observableA. How can I create another Observable observableB which emits value from observableA, but the time between each emission is at least 1000 milliseconds? For example: observableA: X…500ms..Y..1500ms..Z…600ms..T observableB: X..1000ms..Y..1500ms..Z..1000ms..T Source: Angular Questions

How to set default form Value from Observable?

Here is my ts component export interface Product{ id?:string, name:string, price:string; quantity:string; tags:Tags[]; description:string; files: File[]; } product$:Observable<Product | undefined>; ngOnInit(): void { this.store.dispatch(new productActions.LoadProduct(fromProduct.getCurrentProductId.toString())); this.product$ = this.store.pipe(select(fromProduct.getCurrentProduct)); Last and the second statements gather the value of product observable and works fine. this.product = this.fb.group({ name:[”,[ Validators.required, Validators.minLength(1), Validators.maxLength(128) ]], price:[”, Validators.required], tags:this.fb.array(this.tags), quantity:[”,Validators.required], description:[”, […]

1 72

Still Have Questions?


Our dedicated development team is here for you!

We can help you find answers to your question for as low as 5$.

Contact Us
faq