Writing an effect
We successfully created our actions in the previous section. Now, we will make the effects that will be responsible for calling our external API.
Effects are not included in the @ngrx/store
library; we will install a separate library that will allow us to use the functions for effects.
To install effects in our application, we must execute the following command:
ng add @ngrx/effects
The preceding command will perform the following steps:
- Update the
package.json
file with the@
ngrx/effects
dependency. - Run
npm install
to install the added dependency. - Add
EffectsModule.forRoot()
to the imports array of yourapp.module.ts
file.
Some flags are available that allow us to install @ngrx/effects
with customizations; the following is the list of flags we can use:
--path
: Specifies the path to the module where you want to importEffectsModule
.--project
: The name of the project defined inangular.json
.--skipTests
: This creates...