I pass data from parent to its child components via BehaviorSubject
as the following approach (I simplified the approach for brevity):
const subject = new BehaviorSubject(undefined);
// subscriber A
subject.subscribe((data) => {
if(data !== undefined)
ReloadData(data);
else
FirstLoadData();
});
subject.next(myDataObtainedFromDatabase);
In the parent component, I pass the obtained data to all of the components that are subscribed to the subject. On the other hand, I check the data parameter in order to detect if it is the first load or not. At first load I retrieve data from Database, and later I pass the data to the components.
My question is that,
1) by using BehaviorSubject
(I do not want to use Subject
only), is there a better way to load the child components here at first load?
2) For passing data from Parent to Child, is it better to use BehaviorSubject
rather than Input()
property even if the latter seems to be easier to apply?