Questions tagged subject-observer

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

Subject vs BehaviorSubject in Angular

I am passing data between 2 independent components using shared service. When I used a subject in my shared service, I could not see the subscribed data in html of the subscribed component but could see it in the console after subscribing. Whereas if I use Behaviorsubject, it worked fine. Can anyone explain me the […]

How to execute code inside method suscribe() before componant is init

I am trying to make that a component which is subscribed to a Subject executes the code related to the change of state of the Subject before the component is initialized (ngOnInit ()). Here is the CartService: …. import …. @Injectable({ providedIn: ‘root’ }) export class CartService { public updateCartSubject = new Subject<any>(); public cart: […]

RxJS subscribe to change in subscribers count

Problem: I’m using Subject observable to pass String data between components (that are too far apart in the hierarchy). I would like to be able to tell how many subscribers there are to the Subject when a component subscribes or unsubscribes. How can above be achieved? Sorry I’m new to RxJS. Backstory: I have a […]

Angular : Subject is not updating the component

Subject is not updating the component. I have 2 components c1 and c2 and a service class CommonService C1 component having code related to post data. export class C1Component implements OnInit { dBservice: CommonService constructor(private service: CommonService) { this.dBservice = service } ngOnInit(): void { } getData(event, val) { event.preventDefault(); this.SendDataToServer(val) } SendDataToServer(value) { this.dBservice.postData(value).subscribe(data […]

Subject subscribe is not triggering in a component

When I am trying to subscribe to Subject folder_id, it is not subscribing in the board component when I am passing the id in the files component. This boardId function is triggered when a button is pressed in the files component. The activateId is the id taken from the snapshot of the url. boardID(){ this.apiService.folder_id.next(this.activateID.id); […]

Difference between using a variable and using a subject in angular service to create the global variable which can be used throughout the application?

Angular 8 provides us rxjs library , we can use subject from that library to set data that can be used gloabally in our application by declaring it in service file and this same we can do is by declaring just a variable in service file and using it globally in our application . Is […]

Behaviour subject only shows initial value / Replay Subject does not show updated Value

Background: I have a service where I have an open layers based map. The map component has its own service. A pop up is generated when an icon is clicked. On this pop up is a button which when clicked takes some data from the object displayed on the pop up and then navigates to […]

By Blitz Mee
Published
Categorized as angular, behaviorsubject, rxjs, subject-observer

Difference between Subject (being a special case of Observable) and Observable

According to the docs on Subject, it’s a special case of Observable that lets all the observers share a common execution path. The example shows that each observer gets the same emitted values after it’s subscribed to the source. I’m not entirely clear on how it differs from a case of a plan Observable emitting […]

By Konrad Viltersten
Published
Categorized as angular, behaviorsubject, rxjs, subject-observer

Rxjs Behaviour subject not updating data on the UI using ionic 4 and angular 7

I have an array of type BehaviourSubject defined and initialized in a service and it gets updated upon editing it using another function. However the results displayed on the UI are not of the new edited array but the changes are successfully applied to the external database on a server. I have tried many online […]

By Stephen Mutua
Published
Categorized as rxjs6, subject-observer, typescript Tagged ,

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