The constructor runs when the class is instantiated and ensures that the class fields are correctly initialized. Here Angular resolves providers, which you can pass as arguments to your constructor.
The ngOnInit lifecycle hook is called after the data-related properties have been checked for the first time (component inputs and outputs). See this question for a more detailed explanation.
The motivation for choosing from the ngrx repository in the constructor and dispatching from ngOnInit, as I understand it, is that the choice is part of the initialization of your component class. Since this.books$ is observable, it makes sense to initialize it in the constructor, so it is ready for use immediately after creation. Assuming that the value of bookCollection.Load() emits the value of this.books$ , you want this.books$ be observable from these books before the emitted final value.
Since you want these values ββemitted before this.books$ , it makes sense to send the action to ngOnInit. This way you can make sure that this.books$ initialized.
This answer to a similar question may also help.
amu
source share