Questions tagged observable

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

Expect error to be thrown out of next handler of observable, testing Angular with Jasmine

In Angular application have a controller with following method onClick(): void { this.http .get(‘some/endpoint’) .subscribe( (response) => { const editUrl = this.service.composeUrl(response); if (!editUrl) { // want to test this error is thrown, when editUrl is null throw Error(‘Cannot construct valid URL’); } // do something else }, () => { // request clean up […]

How to display FormArray data in FormGroup if such data is dependent on several Observable?

I have wasted several days trying to display asychronously dynamically loaded FormArray data and no luck. In short, I have FormGroup which is created on click and displayed in a modal window (no problem with displaying data loaded in subscribe of Ordinance entity details API call (data is loaded into selectedOrdinance object): buildOrdinanceForm() { this.ordinanceForm […]

By Alexander
Published
Categorized as angular, formarray, observable Tagged , ,

map and filter on observable return empty result

I write an angular 12 application with rxjs that has a products categories list as a service stored in an observable, i am trying to create an observable that will return that categories that has an empty parent_category_id, the problem is that this observable returns an empty list. this is my product category service: import […]

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

infinite http request loop when it’s inside a data service observable and its response used to call a function inside the outer data service (angular)

I want some data that’s inside a data service and is an observable, when I subscribe to the data, I then make an HTTP request and send the data along with it. When the response is received, I then subscribe to it and try to call a function inside the same data service. Here’s the […]

By Ahmad
Published
Categorized as angular, javascript, observable, rxjs Tagged , , ,

using array.filter method how can i check a value from the object of the array and return different value from the same object of the array?

In the code, I am getting an array of objects from the observable and I want to check a value from an object of that array and return a different value from the same object if the condition is satisfied. How can I do that? here is the code: addresses$ = this.addressData$.pipe(map((addressData)=>{ addressData.filter((data)=> {data.deviceType === […]

By krunal
Published
Categorized as angular, arrays, filter, javascript, observable Tagged , , , ,

Angular – TypeError: Cannot read property ‘fromPromise’ of undefined

I have a problem with TypeError: Cannot read property ‘fromPromise’ of undefined. Observable.fromPromise(this.myServiceName.myFunctionName(data)) It looks like the method in the service is undefined. Problem is that this is only on production. When i do it on local env everything is ok. Source: Angular Questions

By PawelD
Published
Categorized as angular, angular-services, observable Tagged , ,

Ngrx store value not displaying in component template

I’m trying to wrap my head around Ngrx, and after reading through the documentation I’ve tried to throw together a quick example using them. My problem is that although the store is set up and the reducers are working as expected (I can see the store updating in redux tools), templates won’t show anything. I’ve […]

By Mr Slug
Published
Categorized as angular, ngrx-store, observable, typescript Tagged , , ,

How to execute function one after another?

I use angular 10 in my project. I have two functions initData1 and initData2. I have two functions: initData1(){ //some http client services } initData2(){ //some http client services } Here how I call functions in my component: ngOnInit(): void { initData1(); initData2(); } My question is how to execute the initData2 function only after […]

Can’t use response in Component View from Subscribe, what is the alternative?

export class Component implements OnInit { obj:string; img:string; username:string = ”; email:string; bio:string; constructor(private authService:AuthService) { this.authService.user .subscribe((userVal) => { this.obj = JSON.stringify(userVal); this.username = userVal.username; console.log(this.username); }) } Now this doesn’t work, you can log the response but not display it in the component view You can find a few hack like this here: […]

By Lajos Bela
Published
Categorized as angular, observable, subscribe Tagged , ,

Why does this RXJS subscription execute the `subscribe` block even if there’s an error?

I have the following code: myFunction() { this.store$ .select(selectFoo, this.fooId) .pipe( switchMap(foo => // THE FOLLOWING API CALL RESULTS IN A 404 this.apiService.someApiCall(foo) .pipe( catchError(error => { alert("There was an error!"); return of(null); }) ) ) ) .subscribe(() => { alert("We are in the subscribe block, proceed assuming success"); }); } When I set it […]

By Salvatore Iovene
Published
Categorized as angular, observable, rxjs Tagged , ,
1 2 3 74

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