Angular
  • Angular learning
  • Angular
    • Change Detection
      • Angular Change Detection Strategies
      • Understanding Change Detection Strategy in Angular
    • Angular Components Overview
      • Lifecycle hooks
      • View encapsulation
    • Text interpolation
    • Pipes
    • ARIA
    • Event binding
    • Directives
    • Dependency injection in Angular
    • Difference between Template-Driven and Reactive Forms
    • Guards
    • Resolvers
      • Resolver example
  • Memory management in Angular applications
  • Renderer2
  • Angular test
    • Testing
      • The different types of tests
      • Some testing best practices
      • Angular Service Testing in Depth
        • About Jasmine
        • Jasmine - Test suites
        • Implementation of First Jasmine Specfication
        • spyOn() & jasmine.createSpyObj()
        • beforeEach()
        • Testing services
        • Disabled and Focused Tests
        • flush
        • HttpTestingController
        • Sample code
      • Angular Component Testing in Depth
        • Intro to Angular Component testing
        • DOM interaction
        • Trigger Change Detection
        • Test Card List Test Suite Conclusion
        • Window.requestAnimationFrame()
        • Asynchronous Work (Jasmine)
        • Cooperative asynchronous JavaScript: Timeouts and intervals
        • FakeAsync - Asynchronous Work (Jasmine) part 2
        • tick()
        • Sample codes
      • Testing Promised-based code-intro Microtasks
        • Microtasks
        • Micro-tasks within an event loop (Summary)
        • Macro-tasks within an event loop (Summary)
        • Test promised Microtasks (code)
      • Using fakeAsync to test Async Observables
      • Cypress.io
        • Create our first e2e test
      • Angular CLI code coverage and deployment in prod mode.
      • Travis CI
  • Angular best practices
    • Angular best practices
      • Security
      • Accessibility in Angular
      • Keeping your Angular projects up-to-date
    • Bootstrapping an Angular Application
      • Understanding the File Structure
      • Bootstrapping Providers
    • Components in Angular
      • Creating Components
      • Application Structure with Components
        • Accessing Child Components from Template
        • Using Two-Way Data Binding
        • Responding to Component Events
        • Passing Data into a Component
      • Projection
      • Structuring Applications with Components
      • Using Other Components
  • Reactive extensions
    • RxJS
      • RxJS Operators
      • of
      • Observable
      • async pipe (Angular)
      • Interval
      • fromEvent
      • Pipe
      • Map
      • Tap
      • ShareReplay
      • Concat
      • ConcatMap
      • Merge
      • MergeMap
      • ExhaustMap
      • fromEvent
      • DebounceTime
        • Type Ahead
      • Distinct Until Changed
      • SwitchMap
      • CatchError
      • Finalize
      • RetryWhen
      • DelayWhen
      • ForkJoin
      • First
      • Interview Questions
      • Zip
  • NgRx
    • What's NgRx
      • Actions
      • Reducers
      • Selectors
      • 🙅‍♂️Authentication guard with NgRX
      • @ngrx/effects
        • Side-Effect refresh survivor
  • Interview Q&A
    • Angular Unit Testing Interview Questions
    • Angular Questions And Answers
  • Angular Advanced
    • Setting up our environment
      • Understanding Accessors (TS)
      • The host & ::ng-deep Pseudo Selector
Powered by GitBook
On this page
  • Introduction
  • Key Concepts
  • Installing with npm
  • Installing with yarn
  • Installing with ng add

Was this helpful?

  1. NgRx
  2. What's NgRx

@ngrx/effects

Previous🙅‍♂️Authentication guard with NgRXNextSide-Effect refresh survivor

Last updated 4 years ago

Was this helpful?

Effects are an RxJS powered side effect model for . Effects use streams to provide of actions to reduce state based on external interactions such as network requests, web socket messages and time-based events.

Introduction

In a service-based Angular application, components are responsible for interacting with external resources directly through services. Instead, effects provide a way to interact with those services and isolate them from the components. Effects are where you handle tasks such as fetching data, long-running tasks that produce multiple events, and other external interactions where your components don't need explicit knowledge of these interactions.

Key Concepts

  • Effects isolate side effects from components, allowing for more pure components that select state and dispatch actions.

  • Effects are long-running services that listen to an observable of every action dispatched from the .

  • Effects filter those actions based on the type of action they are interested in. This is done by using an operator.

  • Effects perform tasks, which are synchronous or asynchronous and return a new action.

Installing with npm

For more information on using npm check out the docs .

content_copynpm install @ngrx/effects --save

Installing with yarn

For more information on using yarn check out the docs .

content_copyyarn add @ngrx/effects

Installing with ng add

content_copyng add @ngrx/effects@latest

Optional ng add flags

  • flat - Indicate if a directory is to be created to hold your effects file

  • skipTests - When true, does not create test files.

  • group - Group effects file within effects folder

This command will automate the following steps:

  1. Update package.json > dependencies with @ngrx/effects.

  2. Run npm install to install those dependencies.

  3. Update your src/app/app.module.ts > imports array with EffectsModule.forRoot([AppEffects]). If you provided flags then the command will attempt to locate and update module found by the flags.

If your project is using the Angular CLI 6+ then you can install the Effects to your project with the following ng add command :

path - path to the module that you wish to add the import for the to.

project - name of the project defined in your angular.json to help locating the module to add the to.

module - name of file containing the module that you wish to add the import for the to. Can also include the relative path to the file. For example, src/app/app.module.ts

minimal - By default true, only provide minimal setup for the root effects setup. Only registers in the provided module with an empty array.

Store
new sources
Store
here
here
(details here)
EffectsModule
EffectsModule
EffectsModule
EffectsModule.forRoot()