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 […]

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