0

Actually unable to find how to bind the data using angular 6 while if share the data with sibling components using subject concept. I separated routing modules for dashboard

In dashboard have to show respective data on click in other component, but it displays in console unable to bind the data in view oninit.

It works in Behaviour subject but not in subject how?

Anyone please help me to learn the concept behind this.

Giving the github path for your reference

https://github.com/uiforchange/AngularComponentLazyLoading.git

Idris
  • 381
  • 2
  • 7
  • 16
  • can you prepare a minimal working example in stackblitz? you have several components/services and would be easy to isolate the problem – Massimo Costa Aug 15 '18 at 06:14

1 Answers1

0

The difference between BehaviorSubject and Subject is that the BehaviorSubject holds an value and immediately emits this value on subscription.
A Subject on the other hand does not hold a value on subscription, which is why you are unable to bind to the data immediately.

You are able to bind to the data you get by changing to BehaviorSubject or by emitting a new value after subscription.

(Taken from this answer)

mahalde
  • 709
  • 5
  • 19
  • But binding happens for the subject also mentioned in the url https://stackblitz.com/edit/angular-rxjs-subject-and-behaviorsubject?file=app%2Fmyservice.ts – Idris Aug 15 '18 at 08:34
  • You are right, but it only happens if the value changed **after** the subscription. – mahalde Aug 15 '18 at 08:44
  • the value changed after the subscription only, but not binds – Idris Aug 15 '18 at 09:29
  • That is correct, but on the subscription there was no value emitted. – mahalde Aug 15 '18 at 09:52
  • In this example you do **not** subscribe on click. You just emit a new value. The subscription happen before. – mahalde Aug 16 '18 at 09:53